mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-23 00:52:31 +08:00
Compare commits
197 Commits
Author | SHA1 | Date | |
---|---|---|---|
46f35129c5 | |||
604c499822 | |||
8964c48ba0 | |||
e85a3e0f1e | |||
c658d393f5 | |||
9a45e29e02 | |||
418ece55e3 | |||
bf455893e7 | |||
6d9cb8205a | |||
0f431e997b | |||
2107df70ad | |||
a9fbea7c96 | |||
77878ddd94 | |||
594abc47f8 | |||
5e326916a2 | |||
31c2debb78 | |||
d919497e43 | |||
0c40b4fad9 | |||
bba912667f | |||
1807e7c5ff | |||
9da2ea9b1b | |||
1a5843f8e1 | |||
25e48f2f37 | |||
1c0011bef9 | |||
9e996816ef | |||
9665753dc8 | |||
942e9d7555 | |||
9efb9581f5 | |||
f10a462b00 | |||
9072b16c5a | |||
21408993c2 | |||
7a8b5b50d1 | |||
1a5e843070 | |||
ade7539fde | |||
5c588e5a03 | |||
af094832fe | |||
af0ee2e690 | |||
d2d6fb4d55 | |||
6c25662fe9 | |||
4bcf82ca10 | |||
ce38e8ac50 | |||
12cd718f12 | |||
995e2a3e93 | |||
2c95fec646 | |||
69912d7ea4 | |||
9c5596ace4 | |||
d4dac58fc8 | |||
77b97cbe17 | |||
c6f0f34ac0 | |||
d1f4f74d32 | |||
f13068bf01 | |||
dfc288a101 | |||
544009dc21 | |||
fdfaaadd89 | |||
58d60a10d4 | |||
0432c6d56c | |||
8c34aa2be5 | |||
4a1c54fac1 | |||
190467fa5c | |||
44f54d9190 | |||
3b4ea31b50 | |||
ad7b05f721 | |||
852ca8e9eb | |||
7386eca0c2 | |||
97325a5f3a | |||
82e52de557 | |||
28181e2266 | |||
6dfa4806ce | |||
27f6a6ca52 | |||
cd7b260ea7 | |||
ba986274be | |||
d181c0bee9 | |||
a9faec8cf9 | |||
a6bf91b7af | |||
e7c5170232 | |||
be635e46a0 | |||
687f56eac9 | |||
1dfcdb2dca | |||
0025c83930 | |||
cfa4b12039 | |||
c7ccdf387c | |||
bb46d77a02 | |||
c38155ab04 | |||
97dbecaa2a | |||
e77e4cce07 | |||
dcf0bdce48 | |||
2a3df5de9d | |||
44ac4312e8 | |||
3494b043bc | |||
c552c4ac5b | |||
4f88d216d9 | |||
095ecd2aeb | |||
5a766682a3 | |||
3963674cb2 | |||
7b03554cd2 | |||
43442587c5 | |||
2f32e29c04 | |||
f946f33d96 | |||
7ac905e1f4 | |||
627a317308 | |||
48e98a1d33 | |||
d379d6b129 | |||
8e2e2abef4 | |||
7920c54761 | |||
fd50996cb2 | |||
5207b1a1c4 | |||
91d5fc284f | |||
4a1125cf1d | |||
2e96d09f67 | |||
8acc85061d | |||
41f0b0ed55 | |||
02eca61f40 | |||
2819ced303 | |||
755eae293e | |||
60580c8183 | |||
e9acd68ee4 | |||
7a4c7eb498 | |||
eb693eceb5 | |||
eedb7dd76f | |||
bc113e9093 | |||
dc449d4a1e | |||
668c8f7c3f | |||
5afebc7d07 | |||
35b0e3808a | |||
4b08cb55f5 | |||
a7f86227fb | |||
2077601464 | |||
6a7596c40b | |||
e4d38af4f5 | |||
70a1570441 | |||
9c077b3aa3 | |||
ca90b64378 | |||
f87b06989d | |||
6766a8cf4c | |||
5e761e2379 | |||
3783638c89 | |||
d038d13867 | |||
2efc3f6578 | |||
e175e9c438 | |||
a46bc11e42 | |||
b9b5d721c8 | |||
f4ba14cd13 | |||
b5b3e90b09 | |||
4263cef26a | |||
626e680510 | |||
b61ac481b9 | |||
ff684d4d4b | |||
7328610252 | |||
fd950e2aef | |||
2256828384 | |||
32684bc63e | |||
648ac941df | |||
0d4b4dc826 | |||
7c85969085 | |||
1fce3465c2 | |||
25747503cc | |||
76c578a9ea | |||
2da293ab21 | |||
88cbd0e970 | |||
a82abe2ec3 | |||
17ee92479c | |||
508ca27ec2 | |||
8949e3dc7d | |||
4280a071f6 | |||
48ed78ec36 | |||
3c964cfef9 | |||
184b037523 | |||
a49a918790 | |||
e3a58bf675 | |||
cc29dbda30 | |||
bc0ad5eab6 | |||
bdf86a7448 | |||
968546d43c | |||
680556d74e | |||
f490203b10 | |||
39d9585f1d | |||
2d414e544b | |||
513fcaa534 | |||
b41f7211e5 | |||
dd6cce1df1 | |||
ad54d2c76b | |||
867370ccee | |||
35eb78ca5d | |||
f1c3771c24 | |||
b012e2305c | |||
e309821743 | |||
56bedc9c6b | |||
59c5b13a05 | |||
b8b6cc1605 | |||
912b1b80ff | |||
6a9c64c2a1 | |||
54deecd312 | |||
403943a41f | |||
e7aa01ebc8 | |||
bf6d526284 | |||
c991cb4b22 | |||
3971e49ce1 |
687
LICENSE
687
LICENSE
@ -1,21 +1,674 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (c) 2020 sinaioutlander
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
247
README.md
247
README.md
@ -1,10 +1,11 @@
|
||||
<p align="center">
|
||||
<img align="center" src="icon.png">
|
||||
<img align="center" src="img/icon.png">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
An in-game explorer and a suite of debugging tools for <a href="https://docs.unity3d.com/Manual/IL2CPP.html">IL2CPP</a> and <b>Mono</b> Unity games, using <a href="https://github.com/HerpDerpinstine/MelonLoader">MelonLoader</a> and <a href="https://github.com/BepInEx/BepInEx">BepInEx</a>.<br><br>
|
||||
|
||||
An in-game explorer and a suite of debugging tools for <a href="https://docs.unity3d.com/Manual/IL2CPP.html">IL2CPP</a> and <b>Mono</b> Unity games, to aid with modding development.
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="../../releases/latest">
|
||||
<img src="https://img.shields.io/github/release/sinai-dev/Explorer.svg" />
|
||||
</a>
|
||||
@ -12,154 +13,144 @@
|
||||
<img src="https://img.shields.io/github/downloads/sinai-dev/Explorer/total.svg" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/sinai-dev/Explorer/master/overview.png">
|
||||
</p>
|
||||
|
||||
- [Current status](#current-status)
|
||||
- [How to install](#how-to-install)
|
||||
- [How to use](#how-to-use)
|
||||
- [Mod Config](#mod-config)
|
||||
- [Releases](#releases)
|
||||
- [Features](#features)
|
||||
- [Mouse Control](#mouse-control)
|
||||
- [How to install](#how-to-install)
|
||||
- [Mod Config](#mod-config)
|
||||
- [Building](#building)
|
||||
- [Credits](#credits)
|
||||
- [Acknowledgments](#acknowledgments)
|
||||
|
||||
## Current status
|
||||
## Releases
|
||||
|
||||
| Mod Loader | Il2Cpp | Mono | Mono (.NET 3.5) |
|
||||
| ----------- | ------ | ---- | ----|
|
||||
| [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) | ✔️ [link](https://github.com/sinai-dev/Explorer/releases/latest/download/Explorer.MelonLoader.Il2Cpp.zip) | ✔️ [link](https://github.com/sinai-dev/Explorer/releases/latest/download/Explorer.MelonLoader.Mono.zip) | ✔️ [link](https://github.com/sinai-dev/Explorer/releases/latest/download/Explorer.MelonLoader.Mono.NET35.zip) |
|
||||
| [BepInEx](https://github.com/BepInEx/BepInEx) | ❔ [link](https://github.com/sinai-dev/Explorer/releases/latest/download/Explorer.BepInEx.Il2Cpp.zip) | ✔️ [link](https://github.com/sinai-dev/Explorer/releases/latest/download/Explorer.BepInEx.Mono.zip) | ✔️ [link](https://github.com/sinai-dev/Explorer/releases/latest/download/Explorer.BepInEx.Mono.NET35.zip) |
|
||||
| Mod Loader | IL2CPP | Mono |
|
||||
| ----------- | ------ | ---- |
|
||||
| [BepInEx](https://github.com/BepInEx/BepInEx) 6.X | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx.Il2Cpp.zip) | ❔* [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx6.Mono.zip) |
|
||||
| [BepInEx](https://github.com/BepInEx/BepInEx) 5.X | ❌ n/a | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx5.Mono.zip) |
|
||||
| [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) 0.3 | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.MelonLoader.Il2Cpp.zip) | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.MelonLoader.Mono.zip) |
|
||||
| Standalone | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Il2Cpp.zip) | ✅ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Mono.zip) |
|
||||
|
||||
<b>IL2CPP Issues:</b>
|
||||
* .NET 3.5 is not currently supported (Unity 5.6.1 and older), this might change in the future.
|
||||
* Some methods may still fail with a `MissingMethodException`, please let me know if you experience this (with full MelonLoader log please).
|
||||
* Reflection may fail with certain types, see [here](https://github.com/knah/Il2CppAssemblyUnhollower#known-issues) for more details.
|
||||
* Scrolling with mouse wheel in the Explorer menu may not work on all games at the moment.
|
||||
|
||||
## How to install
|
||||
|
||||
### MelonLoader
|
||||
Requires [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) to be installed for your game.
|
||||
|
||||
1. Download the relevant <b>Explorer_MelonLoader_.zip</b> from above.
|
||||
2. Unzip the file into the `Mods` folder in your game's installation directory, created by MelonLoader.
|
||||
3. Make sure it's not in a sub-folder, `Explorer.dll` and `mcs.dll` should be directly in the `Mods\` folder.
|
||||
|
||||
### BepInEx
|
||||
Requires [BepInEx](https://github.com/BepInEx/BepInEx) to be installed for your game.
|
||||
|
||||
1. Download the relevant <b>Explorer_BepInEx_.zip</b> from above.
|
||||
2. Unzip the file into the `BepInEx\plugins\` folder in your game's installation directory, created by BepInEx.
|
||||
3. Make sure it's not in a sub-folder, `Explorer.dll` and `mcs.dll` should be directly in the `plugins\` folder.
|
||||
|
||||
## How to use
|
||||
|
||||
* Press F7 to show or hide the menu.
|
||||
* Use the Scene Explorer or the Object Search to start Exploring, or the C# Console to test some code.
|
||||
* See below for more specific details.
|
||||
|
||||
### Mod Config
|
||||
|
||||
There is a simple Mod Config for the Explorer. You can access the settings via the "Options" page of the main menu.
|
||||
|
||||
`Main Menu Toggle` (KeyCode)
|
||||
* Sets the keybinding for the Main Menu toggle (show/hide all Explorer windows)
|
||||
* See [this article](https://docs.unity3d.com/ScriptReference/KeyCode.html) for a full list of all accepted KeyCodes.
|
||||
* Default: `F7`
|
||||
|
||||
`Default Window Size` (Vector2)
|
||||
* Sets the default width and height for all Explorer windows when created.
|
||||
* `x` is width, `y` is height.
|
||||
* Default: `<x>550</x> <y>700</y>`
|
||||
|
||||
`Default Items per Page` (Int)
|
||||
* Sets the default items per page when viewing lists or search results.
|
||||
* Default: `20`
|
||||
\* BepInEx 6.X Mono release may not work on all games yet.
|
||||
|
||||
## Features
|
||||
|
||||
### Scene Explorer
|
||||
<p align="center">
|
||||
<a href="https://raw.githubusercontent.com/sinai-dev/UnityExplorer/master/img/preview.png">
|
||||
<img src="img/preview.png" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
* A simple menu which allows you to traverse the Transform heirarchy of the scene.
|
||||
* Click on a GameObject to set it as the current path, or <b>Inspect</b> it to send it to an Inspector Window.
|
||||
* <b>Scene Explorer</b>: Simple menu to traverse the Transform heirarchy of the scene.
|
||||
* <b>GameObject Inspector</b>: Various helpful tools to see and manipulate the GameObject, similar to what you can do in the Editor.
|
||||
* <b>Reflection Inspector</b>: Inspect Properties and Fields. Can also set primitive values and evaluate primitive methods.
|
||||
* <b>Search</b>: Search for UnityEngine.Objects with various filters, or use the helpers for static Instances and Classes.
|
||||
* <b>C# Console</b>: Interactive console for evaluating C# methods on the fly, with some basic helpers.
|
||||
* <b>Inspect-under-mouse</b>: Hover over an object with a collider and inspect it by clicking on it. There's also a UI mode to inspect UI objects.
|
||||
|
||||
### Inspectors
|
||||
### C# Console Tips
|
||||
|
||||
Explorer has two main inspector modes: <b>GameObject Inspector</b>, and <b>Reflection Inspector</b>.
|
||||
The C# Console can be used to define temporary classes and methods, or it can be used to evaluate an expression, but you cannot do both at the same time.
|
||||
|
||||
<b>Tips:</b>
|
||||
* When in Tab View, GameObjects are denoted by a [G] prefix, and Reflection objects are denoted by a [R] prefix.
|
||||
* Hold <b>Left Shift</b> when you click the Inspect button to force Reflection mode for GameObjects and Transforms.
|
||||
For example, you could run this code to define a temporary class (it will be visible within the console until you run `Reset();`).
|
||||
|
||||
### GameObject Inspector
|
||||
|
||||
* Allows you to see the children and components on a GameObject.
|
||||
* Can use some basic GameObject Controls such as translating and rotating the object, destroy it, clone it, etc.
|
||||
|
||||
### Reflection Inspector
|
||||
|
||||
* The Reflection Inspector is used for all other supported objects.
|
||||
* Allows you to inspect Properties, Fields and basic Methods, as well as set primitive values and evaluate primitive methods.
|
||||
* Can search and filter members for the ones you are interested in.
|
||||
|
||||
### Object Search
|
||||
|
||||
* You can search for an `UnityEngine.Object` with the Object Search feature.
|
||||
* Filter by name, type, etc.
|
||||
* For GameObjects and Transforms you can filter which scene they are found in too.
|
||||
|
||||
### C# console
|
||||
|
||||
* A simple C# console, allows you to execute a method body on the fly.
|
||||
|
||||
### Inspect-under-mouse
|
||||
|
||||
* Press Shift+RMB (Right Mouse Button) while the Explorer menu is open to begin Inspect-Under-Mouse.
|
||||
* Hover over your desired object, if you see the name appear then you can click on it to inspect it.
|
||||
* Only objects with Colliders are supported.
|
||||
|
||||
### Mouse Control
|
||||
|
||||
Explorer can force the mouse to be visible and unlocked when the menu is open, if you have enabled "Force Unlock Mouse" (Left-Alt toggle). However, you may also want to prevent the mouse clicking-through onto the game behind Explorer, this is possible but it requires specific patches for that game.
|
||||
|
||||
* For VRChat, use [VRCExplorerMouseControl](https://github.com/sinai-dev/VRCExplorerMouseControl)
|
||||
* For Hellpoint, use [HPExplorerMouseControl](https://github.com/sinai-dev/Hellpoint-Mods/tree/master/HPExplorerMouseControl/HPExplorerMouseControl)
|
||||
* You can create your own plugin using one of the two plugins above as an example. Usually only a few simple Harmony patches are needed to fix the problem.
|
||||
|
||||
For example:
|
||||
```csharp
|
||||
using Explorer;
|
||||
using Harmony; // or 'using HarmonyLib;' for BepInEx
|
||||
// ...
|
||||
[HarmonyPatch(typeof(MyGame.MenuClass), nameof(MyGame.MenuClass.CursorUpdate)]
|
||||
public class MenuClass_CursorUpdate
|
||||
public class MyClass
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix()
|
||||
public static void Method()
|
||||
{
|
||||
// prevent method running if menu open, let it run if not.
|
||||
return !ExplorerCore.ShowMenu;
|
||||
UnityExplorer.ExplorerCore.Log("hello");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You could then delete or comment out the class and run the following expression to run that method:
|
||||
|
||||
```csharp
|
||||
MyClass.Method();
|
||||
```
|
||||
|
||||
However, you cannot define a class and run it both at the same time. You must either define class(es) and run that, or define an expression and run that.
|
||||
|
||||
You can also make use of the helper methods in the console to simplify some tasks, which you can see listed when the console has nothing entered for input. These methods are **not** accessible within any temporary classes you define, they can only be used in the expression context.
|
||||
|
||||
## How to install
|
||||
|
||||
### BepInEx
|
||||
|
||||
Note: For IL2CPP you should use [BepInEx 6 (Bleeding Edge)](https://builds.bepis.io/projects/bepinex_be), for Mono you should use [BepInEx 5](https://github.com/BepInEx/BepInEx/releases) (until Mono support stabilizes in BepInEx 6).
|
||||
|
||||
0. Install [BepInEx](https://github.com/BepInEx/BepInEx) for your game.
|
||||
1. Download the UnityExplorer release for BepInEx IL2CPP or Mono above.
|
||||
2. Take the `UnityExplorer.BIE.___.dll` file and put it in `[GameFolder]\BepInEx\plugins\`
|
||||
3. In IL2CPP, it is highly recommended to get the base Unity libs for the game's Unity version and put them in the `BepInEx\unity-libs\` folder.
|
||||
|
||||
### MelonLoader
|
||||
|
||||
Note: You must use version 0.3 of MelonLoader or greater. Version 0.3 is currently in pre-release, so you must opt-in from your MelonLoader installer (enable alpha releases).
|
||||
|
||||
0. Install [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) for your game.
|
||||
1. Download the UnityExplorer release for MelonLoader IL2CPP or Mono above.
|
||||
2. Take the contents of the release and put it in the `[GameFolder]\Mods\` folder. It should look like `[GameFolder]\Mods\UnityExplorer.ML.___.dll`
|
||||
|
||||
### Standalone
|
||||
|
||||
The standalone release is based on the BepInEx build, so it requires Harmony 2.0 (or HarmonyX) to function properly.
|
||||
|
||||
0. Load the DLL from your mod or inject it. You must also make sure that the required libraries (Harmony, Unhollower for Il2Cpp, etc) are loaded.
|
||||
1. Create an instance of Unity Explorer with `ExplorerStandalone.CreateInstance();`
|
||||
2. Optionally subscribe to the `ExplorerStandalone.OnLog` event to handle logging if you wish.
|
||||
|
||||
## Logging
|
||||
|
||||
Explorer saves all logs to disk (only keeps the most recent 10 logs). They can be found in a "UnityExplorer" folder in the same place as where you put the DLL file.
|
||||
|
||||
These logs are also visible in the Debug Console part of the UI.
|
||||
|
||||
## Settings
|
||||
|
||||
You can change the settings via the "Options" page of the main menu, or directly from the config file (generated after first launch). The config file will be found either inside a "UnityExplorer" folder in the same directory as where you put the DLL file, or for BepInEx it will be at `BepInEx\config\UnityExplorer\`.
|
||||
|
||||
`Main Menu Toggle` (KeyCode)
|
||||
* Default: `F7`
|
||||
* See [this article](https://docs.unity3d.com/ScriptReference/KeyCode.html) for a full list of all accepted KeyCodes.
|
||||
|
||||
`Force Unlock Mouse` (bool)
|
||||
* Default: `true`
|
||||
* Forces the cursor to be unlocked and visible while the UnityExplorer menu is open, and prevents anything else taking control.
|
||||
|
||||
`Default Page Limit` (int)
|
||||
* Default: `25`
|
||||
* Sets the default items per page when viewing lists or search results.
|
||||
* <b>Requires a restart to take effect</b>, apart from Reflection Inspector tabs.
|
||||
|
||||
`Default Output Path` (string)
|
||||
* Default: `Mods\UnityExplorer`
|
||||
* Where output is generated to, by default (for Texture PNG saving, etc).
|
||||
|
||||
`Log Unity Debug` (bool)
|
||||
* Default: `false`
|
||||
* Listens for Unity `Debug.Log` messages and prints them to UnityExplorer's log.
|
||||
|
||||
`Hide on Startup` (bool)
|
||||
* Default: `false`
|
||||
* If true, UnityExplorer will be hidden when you start the game, you must open it via the keybind.
|
||||
|
||||
## Building
|
||||
|
||||
If you'd like to build this yourself, everything you need (other than MelonLoader) is included with this repository, there is no need for recursive cloning etc.
|
||||
If you'd like to build this yourself, all you need to do is download this repository and build from Visual Studio.
|
||||
|
||||
1. Install MelonLoader for your game.
|
||||
2. Open the `src\Explorer.csproj` file in a text editor.
|
||||
3. Set the relevant `GameFolder` value(s) for the version(s) you want to build, eg. set `MLCppGameFolder` if you want to build for a MelonLoader Il2Cpp game.
|
||||
4. Open the `src\Explorer.sln` project.
|
||||
5. Select `Solution 'Explorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> to the version you want to build, then build it.
|
||||
5. The DLLs are built to the `Release\` folder in the root of the repository.
|
||||
1. Open the `src\UnityExplorer.sln` project.
|
||||
2. Select `Solution 'UnityExplorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> property to the version you want to build, then build it. Alternatively, use "Batch Build" and select all releases.
|
||||
3. The DLLs are built to the `Release\` folder in the root of the repository.
|
||||
|
||||
## Credits
|
||||
The references are all inside the `lib\` folder, if you need to change them for some reason then you can replace them there.
|
||||
|
||||
Written by Sinai.
|
||||
## Acknowledgments
|
||||
|
||||
Thanks to:
|
||||
* [ManlyMarco](https://github.com/ManlyMarco) for their [Runtime Unity Editor](https://github.com/ManlyMarco/RuntimeUnityEditor), which I used for the REPL Console and the "Find instances" snippet, and the UI style.
|
||||
* [denikson](https://github.com/denikson) for [mcs-unity](https://github.com/denikson/mcs-unity). I commented out the `SkipVisibilityExt` constructor since it was causing an exception with the Hook it attempted.
|
||||
* [ManlyMarco](https://github.com/ManlyMarco) for [Runtime Unity Editor](https://github.com/ManlyMarco/RuntimeUnityEditor) (GPL), snippets from the REPL Console were used for UnityExplorer's C# Console.
|
||||
* [denikson](https://github.com/denikson) (aka Horse) for [mcs-unity](https://github.com/denikson/mcs-unity) (MIT), used as the `Mono.CSharp` reference for the C# Console.
|
||||
* [HerpDerpenstine](https://github.com/HerpDerpinstine) for [MelonCoroutines](https://github.com/LavaGang/MelonLoader/blob/master/MelonLoader.Support.Il2Cpp/MelonCoroutines.cs) (Apache), they were included for standalone Il2CPP coroutine support.
|
||||
* [InGameCodeEditor](https://assetstore.unity.com/packages/tools/gui/ingame-code-editor-144254) (Apache) was used as the base for the syntax highlighting for UnityExplorer's C# console (`UnityExplorer.UI.Main.CSConsole.Lexer`).
|
||||
|
||||
### Disclaimer
|
||||
|
||||
UnityExplorer is in no way associated with Unity Technologies. "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere.
|
||||
|
BIN
img/icon.png
Normal file
BIN
img/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
img/preview.png
Normal file
BIN
img/preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 407 KiB |
BIN
img/social.png
Normal file
BIN
img/social.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 200 KiB |
BIN
lib/0Harmony.dll
Normal file
BIN
lib/0Harmony.dll
Normal file
Binary file not shown.
BIN
lib/BepInEx.Core.dll
Normal file
BIN
lib/BepInEx.Core.dll
Normal file
Binary file not shown.
BIN
lib/BepInEx.IL2CPP.dll
Normal file
BIN
lib/BepInEx.IL2CPP.dll
Normal file
Binary file not shown.
BIN
lib/BepInEx.Unity.dll
Normal file
BIN
lib/BepInEx.Unity.dll
Normal file
Binary file not shown.
BIN
lib/BepInEx.dll
Normal file
BIN
lib/BepInEx.dll
Normal file
Binary file not shown.
BIN
lib/INIFileParser.dll
Normal file
BIN
lib/INIFileParser.dll
Normal file
Binary file not shown.
BIN
lib/MelonLoader.dll
Normal file
BIN
lib/MelonLoader.dll
Normal file
Binary file not shown.
BIN
lib/UnhollowerBaseLib.dll
Normal file
BIN
lib/UnhollowerBaseLib.dll
Normal file
Binary file not shown.
BIN
lib/UnityEngine.UI.dll
Normal file
BIN
lib/UnityEngine.UI.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/mcs.dll
BIN
lib/mcs.dll
Binary file not shown.
BIN
lib/unhollowed/Il2CppSystem.Core.dll
Normal file
BIN
lib/unhollowed/Il2CppSystem.Core.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/Il2Cppmscorlib.dll
Normal file
BIN
lib/unhollowed/Il2Cppmscorlib.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.CoreModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.CoreModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.IMGUIModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.IMGUIModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.PhysicsModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.PhysicsModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.TextRenderingModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.TextRenderingModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.UI.dll
Normal file
BIN
lib/unhollowed/UnityEngine.UI.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.UIModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.UIModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.dll
Normal file
BIN
lib/unhollowed/UnityEngine.dll
Normal file
Binary file not shown.
BIN
overview.png
BIN
overview.png
Binary file not shown.
Before Width: | Height: | Size: 479 KiB |
@ -1,169 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public static class CacheFactory
|
||||
{
|
||||
public static CacheObjectBase GetTypeAndCacheObject(object obj)
|
||||
=> GetTypeAndCacheObject(obj, null, null);
|
||||
|
||||
public static CacheObjectBase GetTypeAndCacheObject(MemberInfo memberInfo, object declarer)
|
||||
=> GetTypeAndCacheObject(null, memberInfo, declarer);
|
||||
|
||||
public static CacheObjectBase GetTypeAndCacheObject(object obj, MemberInfo memberInfo, object declarer)
|
||||
{
|
||||
Type type = null;
|
||||
|
||||
if (memberInfo != null)
|
||||
{
|
||||
if (memberInfo is FieldInfo fi)
|
||||
{
|
||||
type = fi.FieldType;
|
||||
}
|
||||
else if (memberInfo is PropertyInfo pi)
|
||||
{
|
||||
type = pi.PropertyType;
|
||||
}
|
||||
else if (memberInfo is MethodInfo mi)
|
||||
{
|
||||
type = mi.ReturnType;
|
||||
}
|
||||
}
|
||||
else if (obj != null)
|
||||
{
|
||||
type = ReflectionHelpers.GetActualType(obj);
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetCacheObject(obj, memberInfo, declarer, type);
|
||||
}
|
||||
|
||||
public static CacheObjectBase GetCacheObject(object obj, Type valueType)
|
||||
=> GetCacheObject(obj, null, null, valueType);
|
||||
|
||||
private static CacheObjectBase GetCacheObject(object obj, MemberInfo memberInfo, object declaringInstance, Type valueType)
|
||||
{
|
||||
CacheObjectBase cached;
|
||||
|
||||
var pi = memberInfo as PropertyInfo;
|
||||
var mi = memberInfo as MethodInfo;
|
||||
|
||||
// Check if can process args
|
||||
if ((pi != null && !CanProcessArgs(pi.GetIndexParameters()))
|
||||
|| (mi != null && !CanProcessArgs(mi.GetParameters())))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (mi != null)
|
||||
{
|
||||
cached = new CacheMethod();
|
||||
}
|
||||
else if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
||||
{
|
||||
cached = new CacheGameObject();
|
||||
}
|
||||
else if (valueType.IsPrimitive || valueType == typeof(string))
|
||||
{
|
||||
cached = new CachePrimitive();
|
||||
}
|
||||
else if (valueType.IsEnum)
|
||||
{
|
||||
if (valueType.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] attributes && attributes.Length > 0)
|
||||
{
|
||||
cached = new CacheEnumFlags();
|
||||
}
|
||||
else
|
||||
{
|
||||
cached = new CacheEnum();
|
||||
}
|
||||
}
|
||||
else if (valueType == typeof(Vector2) || valueType == typeof(Vector3) || valueType == typeof(Vector4))
|
||||
{
|
||||
cached = new CacheVector();
|
||||
}
|
||||
else if (valueType == typeof(Quaternion))
|
||||
{
|
||||
cached = new CacheQuaternion();
|
||||
}
|
||||
else if (valueType == typeof(Color))
|
||||
{
|
||||
cached = new CacheColor();
|
||||
}
|
||||
else if (valueType == typeof(Rect))
|
||||
{
|
||||
cached = new CacheRect();
|
||||
}
|
||||
// must check this before IsEnumerable
|
||||
else if (ReflectionHelpers.IsDictionary(valueType))
|
||||
{
|
||||
cached = new CacheDictionary();
|
||||
}
|
||||
else if (ReflectionHelpers.IsEnumerable(valueType))
|
||||
{
|
||||
cached = new CacheList();
|
||||
}
|
||||
else
|
||||
{
|
||||
cached = new CacheOther();
|
||||
}
|
||||
|
||||
cached.Value = obj;
|
||||
cached.ValueType = valueType;
|
||||
|
||||
if (memberInfo != null)
|
||||
{
|
||||
cached.MemInfo = memberInfo;
|
||||
cached.DeclaringType = memberInfo.DeclaringType;
|
||||
cached.DeclaringInstance = declaringInstance;
|
||||
}
|
||||
|
||||
if (pi != null)
|
||||
{
|
||||
cached.m_arguments = pi.GetIndexParameters();
|
||||
}
|
||||
else if (mi != null)
|
||||
{
|
||||
cached.m_arguments = mi.GetParameters();
|
||||
}
|
||||
|
||||
cached.m_argumentInput = new string[cached.m_arguments.Length];
|
||||
|
||||
cached.UpdateValue();
|
||||
|
||||
cached.Init();
|
||||
|
||||
return cached;
|
||||
}
|
||||
|
||||
public static bool CanProcessArgs(ParameterInfo[] parameters)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
var pType = param.ParameterType;
|
||||
|
||||
if (pType.IsByRef && pType.HasElementType)
|
||||
{
|
||||
pType = pType.GetElementType();
|
||||
}
|
||||
|
||||
if (pType.IsPrimitive || pType == typeof(string))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,430 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public abstract class CacheObjectBase
|
||||
{
|
||||
public object Value;
|
||||
public Type ValueType;
|
||||
|
||||
public MemberInfo MemInfo { get; set; }
|
||||
public Type DeclaringType { get; set; }
|
||||
public object DeclaringInstance { get; set; }
|
||||
|
||||
public virtual bool HasParameters => m_arguments != null && m_arguments.Length > 0;
|
||||
|
||||
public bool m_evaluated = false;
|
||||
public bool m_isEvaluating;
|
||||
public ParameterInfo[] m_arguments = new ParameterInfo[0];
|
||||
public string[] m_argumentInput = new string[0];
|
||||
|
||||
public string ReflectionException { get; set; }
|
||||
|
||||
public string RichTextName => m_richTextName ?? GetRichTextName();
|
||||
private string m_richTextName;
|
||||
|
||||
public bool CanWrite => m_canWrite ?? GetCanWrite();
|
||||
private bool? m_canWrite;
|
||||
|
||||
public virtual void Init() { }
|
||||
|
||||
public abstract void DrawValue(Rect window, float width);
|
||||
|
||||
public virtual void UpdateValue()
|
||||
{
|
||||
if (MemInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasParameters && !m_isEvaluating)
|
||||
{
|
||||
// Need to enter parameters first
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (MemInfo.MemberType == MemberTypes.Field)
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance);
|
||||
}
|
||||
else if (MemInfo.MemberType == MemberTypes.Property)
|
||||
{
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||
|
||||
Value = pi.GetValue(target, ParseArguments());
|
||||
}
|
||||
|
||||
ReflectionException = null;
|
||||
m_evaluated = true;
|
||||
m_isEvaluating = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (MemInfo.MemberType == MemberTypes.Field)
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
fi.SetValue(fi.IsStatic ? null : DeclaringInstance, Value);
|
||||
}
|
||||
else if (MemInfo.MemberType == MemberTypes.Property)
|
||||
{
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
|
||||
if (HasParameters)
|
||||
{
|
||||
pi.SetValue(pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance, Value, ParseArguments());
|
||||
}
|
||||
else
|
||||
{
|
||||
pi.SetValue(pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance, Value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Error setting value: {e.GetType()}, {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ParseArguments()
|
||||
{
|
||||
var parsedArgs = new List<object>();
|
||||
for (int i = 0; i < m_arguments.Length; i++)
|
||||
{
|
||||
var input = m_argumentInput[i];
|
||||
var type = m_arguments[i].ParameterType;
|
||||
|
||||
if (type.IsByRef)
|
||||
{
|
||||
type = type.GetElementType();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
if (type == typeof(string))
|
||||
{
|
||||
parsedArgs.Add(input);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var arg = type.GetMethod("Parse", new Type[] { typeof(string) })
|
||||
.Invoke(null, new object[] { input });
|
||||
|
||||
parsedArgs.Add(arg);
|
||||
continue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
ExplorerCore.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No input, see if there is a default value.
|
||||
if (HasDefaultValue(m_arguments[i]))
|
||||
{
|
||||
parsedArgs.Add(m_arguments[i].DefaultValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try add a null arg I guess
|
||||
parsedArgs.Add(null);
|
||||
}
|
||||
|
||||
return parsedArgs.ToArray();
|
||||
}
|
||||
|
||||
public static bool HasDefaultValue(ParameterInfo arg) => arg.DefaultValue != DBNull.Value;
|
||||
|
||||
// ========= Gui Draw ==========
|
||||
|
||||
public const float MAX_LABEL_WIDTH = 400f;
|
||||
public const string EVALUATE_LABEL = "<color=lime>Evaluate</color>";
|
||||
|
||||
public float CalcWhitespace(Rect window)
|
||||
{
|
||||
if (!(this is IExpandHeight)) return 0f;
|
||||
|
||||
float whitespace = (this as IExpandHeight).WhiteSpace;
|
||||
if (whitespace > 0)
|
||||
{
|
||||
ClampLabelWidth(window, ref whitespace);
|
||||
}
|
||||
|
||||
return whitespace;
|
||||
}
|
||||
|
||||
public static void ClampLabelWidth(Rect window, ref float labelWidth)
|
||||
{
|
||||
float min = window.width * 0.37f;
|
||||
if (min > MAX_LABEL_WIDTH) min = MAX_LABEL_WIDTH;
|
||||
|
||||
labelWidth = Mathf.Clamp(labelWidth, min, MAX_LABEL_WIDTH);
|
||||
}
|
||||
|
||||
public void Draw(Rect window, float labelWidth = 215f)
|
||||
{
|
||||
if (labelWidth > 0)
|
||||
{
|
||||
ClampLabelWidth(window, ref labelWidth);
|
||||
}
|
||||
|
||||
if (MemInfo != null)
|
||||
{
|
||||
GUILayout.Label(RichTextName, new GUILayoutOption[] { GUILayout.Width(labelWidth) });
|
||||
}
|
||||
else
|
||||
{
|
||||
GUIUnstrip.Space(labelWidth);
|
||||
}
|
||||
|
||||
var cm = this as CacheMethod;
|
||||
|
||||
if (HasParameters)
|
||||
{
|
||||
GUILayout.BeginVertical(new GUILayoutOption[0]);
|
||||
|
||||
if (m_isEvaluating)
|
||||
{
|
||||
if (cm != null && cm.GenericArgs.Length > 0)
|
||||
{
|
||||
GUILayout.Label($"<b><color=orange>Generic Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
|
||||
for (int i = 0; i < cm.GenericArgs.Length; i++)
|
||||
{
|
||||
string types = "";
|
||||
if (cm.GenericConstraints[i].Length > 0)
|
||||
{
|
||||
foreach (var constraint in cm.GenericConstraints[i])
|
||||
{
|
||||
if (types != "") types += ", ";
|
||||
|
||||
string type;
|
||||
|
||||
if (constraint == null)
|
||||
type = "Any";
|
||||
else
|
||||
type = constraint.ToString();
|
||||
|
||||
types += $"<color={UIStyles.Syntax.Class_Instance}>{type}</color>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
types = $"<color={UIStyles.Syntax.Class_Instance}>Any</color>";
|
||||
}
|
||||
var input = cm.GenericArgInput[i];
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
GUILayout.Label(
|
||||
$"<color={UIStyles.Syntax.StructGreen}>{cm.GenericArgs[i].Name}</color>",
|
||||
new GUILayoutOption[] { GUILayout.Width(15) }
|
||||
);
|
||||
cm.GenericArgInput[i] = GUIUnstrip.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
GUILayout.Label(types, new GUILayoutOption[0]);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_arguments.Length > 0)
|
||||
{
|
||||
GUILayout.Label($"<b><color=orange>Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
for (int i = 0; i < m_arguments.Length; i++)
|
||||
{
|
||||
var name = m_arguments[i].Name;
|
||||
var input = m_argumentInput[i];
|
||||
var type = m_arguments[i].ParameterType.Name;
|
||||
|
||||
var label = $"<color={UIStyles.Syntax.Class_Instance}>{type}</color> ";
|
||||
label += $"<color={UIStyles.Syntax.Local}>{name}</color>";
|
||||
if (HasDefaultValue(m_arguments[i]))
|
||||
{
|
||||
label = $"<i>[{label} = {m_arguments[i].DefaultValue ?? "null"}]</i>";
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(15) });
|
||||
m_argumentInput[i] = GUIUnstrip.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
GUILayout.Label(label, new GUILayoutOption[0]);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) }))
|
||||
{
|
||||
if (cm != null)
|
||||
cm.Evaluate();
|
||||
else
|
||||
UpdateValue();
|
||||
}
|
||||
if (GUILayout.Button("Cancel", new GUILayoutOption[] { GUILayout.Width(70) }))
|
||||
{
|
||||
m_isEvaluating = false;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
var lbl = $"Evaluate (";
|
||||
int len = m_arguments.Length;
|
||||
if (cm != null) len += cm.GenericArgs.Length;
|
||||
lbl += len + " params)";
|
||||
|
||||
if (GUILayout.Button(lbl, new GUILayoutOption[] { GUILayout.Width(150) }))
|
||||
{
|
||||
m_isEvaluating = true;
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(labelWidth);
|
||||
}
|
||||
else if (cm != null)
|
||||
{
|
||||
if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) }))
|
||||
{
|
||||
cm.Evaluate();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(labelWidth);
|
||||
}
|
||||
|
||||
string typeName = $"<color={UIStyles.Syntax.Class_Instance}>{ValueType.FullName}</color>";
|
||||
|
||||
if (!string.IsNullOrEmpty(ReflectionException))
|
||||
{
|
||||
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", new GUILayoutOption[0]);
|
||||
}
|
||||
else if ((HasParameters || this is CacheMethod) && !m_evaluated)
|
||||
{
|
||||
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> ({typeName})", new GUILayoutOption[0]);
|
||||
}
|
||||
else if (Value == null && !(this is CacheMethod))
|
||||
{
|
||||
GUILayout.Label($"<i>null ({typeName})</i>", new GUILayoutOption[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawValue(window, window.width - labelWidth - 90);
|
||||
}
|
||||
}
|
||||
|
||||
private bool GetCanWrite()
|
||||
{
|
||||
if (MemInfo is FieldInfo fi)
|
||||
m_canWrite = !(fi.IsLiteral && !fi.IsInitOnly);
|
||||
else if (MemInfo is PropertyInfo pi)
|
||||
m_canWrite = pi.CanWrite;
|
||||
else
|
||||
m_canWrite = false;
|
||||
|
||||
return (bool)m_canWrite;
|
||||
}
|
||||
|
||||
private string GetRichTextName()
|
||||
{
|
||||
string memberColor = "";
|
||||
bool isStatic = false;
|
||||
|
||||
if (MemInfo is FieldInfo fi)
|
||||
{
|
||||
if (fi.IsStatic)
|
||||
{
|
||||
isStatic = true;
|
||||
memberColor = UIStyles.Syntax.Field_Static;
|
||||
}
|
||||
else
|
||||
memberColor = UIStyles.Syntax.Field_Instance;
|
||||
}
|
||||
else if (MemInfo is MethodInfo mi)
|
||||
{
|
||||
if (mi.IsStatic)
|
||||
{
|
||||
isStatic = true;
|
||||
memberColor = UIStyles.Syntax.Method_Static;
|
||||
}
|
||||
else
|
||||
memberColor = UIStyles.Syntax.Method_Instance;
|
||||
}
|
||||
else if (MemInfo is PropertyInfo pi)
|
||||
{
|
||||
if (pi.GetAccessors()[0].IsStatic)
|
||||
{
|
||||
isStatic = true;
|
||||
memberColor = UIStyles.Syntax.Prop_Static;
|
||||
}
|
||||
else
|
||||
memberColor = UIStyles.Syntax.Prop_Instance;
|
||||
}
|
||||
|
||||
string classColor;
|
||||
if (MemInfo.DeclaringType.IsValueType)
|
||||
{
|
||||
classColor = UIStyles.Syntax.StructGreen;
|
||||
}
|
||||
else if (MemInfo.DeclaringType.IsAbstract && MemInfo.DeclaringType.IsSealed)
|
||||
{
|
||||
classColor = UIStyles.Syntax.Class_Static;
|
||||
}
|
||||
else
|
||||
{
|
||||
classColor = UIStyles.Syntax.Class_Instance;
|
||||
}
|
||||
|
||||
m_richTextName = $"<color={classColor}>{MemInfo.DeclaringType.Name}</color>.";
|
||||
if (isStatic) m_richTextName += "<i>";
|
||||
m_richTextName += $"<color={memberColor}>{MemInfo.Name}</color>";
|
||||
if (isStatic) m_richTextName += "</i>";
|
||||
|
||||
// generic method args
|
||||
if (this is CacheMethod cm && cm.GenericArgs.Length > 0)
|
||||
{
|
||||
m_richTextName += "<";
|
||||
|
||||
var args = "";
|
||||
for (int i = 0; i < cm.GenericArgs.Length; i++)
|
||||
{
|
||||
if (args != "") args += ", ";
|
||||
args += $"<color={UIStyles.Syntax.StructGreen}>{cm.GenericArgs[i].Name}</color>";
|
||||
}
|
||||
m_richTextName += args;
|
||||
|
||||
m_richTextName += ">";
|
||||
}
|
||||
|
||||
return m_richTextName;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace Explorer
|
||||
{
|
||||
interface IExpandHeight
|
||||
{
|
||||
bool IsExpanded { get; set; }
|
||||
float WhiteSpace { get; set; }
|
||||
}
|
||||
}
|
@ -1,286 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
#endif
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheDictionary : CacheObjectBase, IExpandHeight
|
||||
{
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public PageHelper Pages = new PageHelper();
|
||||
|
||||
private CacheObjectBase[] m_cachedKeys;
|
||||
private CacheObjectBase[] m_cachedValues;
|
||||
|
||||
public Type TypeOfKeys
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_keysType == null) GetGenericArguments();
|
||||
return m_keysType;
|
||||
}
|
||||
}
|
||||
private Type m_keysType;
|
||||
|
||||
public Type TypeOfValues
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_valuesType == null) GetGenericArguments();
|
||||
return m_valuesType;
|
||||
}
|
||||
}
|
||||
private Type m_valuesType;
|
||||
|
||||
public IDictionary IDict
|
||||
{
|
||||
get => m_iDictionary ?? (m_iDictionary = Value as IDictionary) ?? Il2CppDictionaryToMono();
|
||||
set => m_iDictionary = value;
|
||||
}
|
||||
private IDictionary m_iDictionary;
|
||||
|
||||
// ========== Methods ==========
|
||||
|
||||
// This is a bit janky due to Il2Cpp Dictionary not implementing IDictionary.
|
||||
private IDictionary Il2CppDictionaryToMono()
|
||||
{
|
||||
// note: "ValueType" is the Dictionary itself, TypeOfValues is the 'Dictionary.Values' type.
|
||||
|
||||
// get keys and values
|
||||
var keys = ValueType.GetProperty("Keys") .GetValue(Value, null);
|
||||
var values = ValueType.GetProperty("Values").GetValue(Value, null);
|
||||
|
||||
// create lists to hold them
|
||||
var keyList = new List<object>();
|
||||
var valueList = new List<object>();
|
||||
|
||||
// store entries with reflection
|
||||
EnumerateWithReflection(keys, keyList);
|
||||
EnumerateWithReflection(values, valueList);
|
||||
|
||||
// make actual mono dictionary
|
||||
var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>)
|
||||
.MakeGenericType(TypeOfKeys, TypeOfValues));
|
||||
|
||||
// finally iterate into dictionary
|
||||
for (int i = 0; i < keyList.Count; i++)
|
||||
{
|
||||
dict.Add(keyList[i], valueList[i]);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private void EnumerateWithReflection(object collection, List<object> list)
|
||||
{
|
||||
// invoke GetEnumerator
|
||||
var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null);
|
||||
// get the type of it
|
||||
var enumeratorType = enumerator.GetType();
|
||||
// reflect MoveNext and Current
|
||||
var moveNext = enumeratorType.GetMethod("MoveNext");
|
||||
var current = enumeratorType.GetProperty("Current");
|
||||
// iterate
|
||||
while ((bool)moveNext.Invoke(enumerator, null))
|
||||
{
|
||||
list.Add(current.GetValue(enumerator, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void GetGenericArguments()
|
||||
{
|
||||
if (ValueType.IsGenericType)
|
||||
{
|
||||
m_keysType = ValueType.GetGenericArguments()[0];
|
||||
m_valuesType = ValueType.GetGenericArguments()[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's non-generic, just use System.Object to allow for anything.
|
||||
m_keysType = typeof(object);
|
||||
m_valuesType = typeof(object);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
// first make sure we won't run into a TypeInitializationException.
|
||||
if (!EnsureDictionaryIsSupported())
|
||||
{
|
||||
ReflectionException = "Dictionary Type not supported with Reflection!";
|
||||
return;
|
||||
}
|
||||
|
||||
base.UpdateValue();
|
||||
|
||||
// reset
|
||||
IDict = null;
|
||||
|
||||
if (Value == null || IDict == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = new List<CacheObjectBase>();
|
||||
foreach (var key in IDict.Keys)
|
||||
{
|
||||
Type t = ReflectionHelpers.GetActualType(key) ?? TypeOfKeys;
|
||||
var cache = CacheFactory.GetCacheObject(key, t);
|
||||
keys.Add(cache);
|
||||
}
|
||||
|
||||
var values = new List<CacheObjectBase>();
|
||||
foreach (var val in IDict.Values)
|
||||
{
|
||||
Type t = ReflectionHelpers.GetActualType(val) ?? TypeOfValues;
|
||||
var cache = CacheFactory.GetCacheObject(val, t);
|
||||
values.Add(cache);
|
||||
}
|
||||
|
||||
m_cachedKeys = keys.ToArray();
|
||||
m_cachedValues = values.ToArray();
|
||||
}
|
||||
|
||||
private bool EnsureDictionaryIsSupported()
|
||||
{
|
||||
if (typeof(IDictionary).IsAssignableFrom(ValueType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#if CPP
|
||||
try
|
||||
{
|
||||
return Check(TypeOfKeys) && Check(TypeOfValues);
|
||||
|
||||
bool Check(Type type)
|
||||
{
|
||||
var ptr = (IntPtr)typeof(Il2CppClassPointerStore<>)
|
||||
.MakeGenericType(type)
|
||||
.GetField("NativeClassPtr")
|
||||
.GetValue(null);
|
||||
|
||||
return Il2CppSystem.Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is Il2CppSystem.Type;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ============= GUI Draw =============
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (m_cachedKeys == null || m_cachedValues == null)
|
||||
{
|
||||
GUILayout.Label("Cached keys or values is null!", new GUILayoutOption[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
int count = m_cachedKeys.Length;
|
||||
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
var negativeWhitespace = window.width - (whitespace + 100f);
|
||||
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
string btnLabel = $"[{count}] <color=#2df7b2>Dictionary<{TypeOfKeys.FullName}, {TypeOfValues.FullName}></color>";
|
||||
if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.Width(negativeWhitespace) }))
|
||||
{
|
||||
WindowManager.InspectObject(Value, out bool _);
|
||||
}
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
GUIUnstrip.Space(5);
|
||||
|
||||
if (IsExpanded)
|
||||
{
|
||||
Pages.ItemCount = count;
|
||||
|
||||
if (count > Pages.ItemsPerPage)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUIUnstrip.Space(whitespace);
|
||||
|
||||
Pages.CurrentPageLabel();
|
||||
|
||||
// prev/next page buttons
|
||||
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||
{
|
||||
Pages.TurnPage(Turn.Left);
|
||||
}
|
||||
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||
{
|
||||
Pages.TurnPage(Turn.Right);
|
||||
}
|
||||
|
||||
Pages.DrawLimitInputArea();
|
||||
|
||||
GUIUnstrip.Space(5);
|
||||
}
|
||||
|
||||
int offset = Pages.CalculateOffsetIndex();
|
||||
|
||||
for (int i = offset; i < offset + Pages.ItemsPerPage && i < count; i++)
|
||||
{
|
||||
var key = m_cachedKeys[i];
|
||||
var val = m_cachedValues[i];
|
||||
|
||||
//collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
//GUIUnstrip.Space(whitespace);
|
||||
|
||||
if (key == null || val == null)
|
||||
{
|
||||
GUILayout.Label($"[{i}] <i><color=grey>(null)</color></i>", new GUILayoutOption[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) });
|
||||
key.DrawValue(window, (window.width / 2) - 80f);
|
||||
|
||||
GUILayout.Label("Value:", new GUILayoutOption[] { GUILayout.Width(40) });
|
||||
val.DrawValue(window, (window.width / 2) - 80f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheGameObject : CacheObjectBase
|
||||
{
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
UIHelpers.GOButton(Value, null, false, width);
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,367 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheList : CacheObjectBase, IExpandHeight
|
||||
{
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public PageHelper Pages = new PageHelper();
|
||||
|
||||
private CacheObjectBase[] m_cachedEntries;
|
||||
|
||||
// Type of Entries in the Array
|
||||
public Type EntryType
|
||||
{
|
||||
get => GetEntryType();
|
||||
set => m_entryType = value;
|
||||
}
|
||||
private Type m_entryType;
|
||||
|
||||
// Cached IEnumerable object
|
||||
public IEnumerable Enumerable
|
||||
{
|
||||
get => GetEnumerable();
|
||||
}
|
||||
private IEnumerable m_enumerable;
|
||||
|
||||
// Generic Type Definition for Lists
|
||||
public Type GenericTypeDef
|
||||
{
|
||||
get => GetGenericTypeDef();
|
||||
}
|
||||
private Type m_genericTypeDef;
|
||||
|
||||
// Cached ToArray method for Lists
|
||||
public MethodInfo CppListToArrayMethod
|
||||
{
|
||||
get => GetGenericToArrayMethod();
|
||||
}
|
||||
private MethodInfo m_genericToArray;
|
||||
|
||||
// Cached Item Property for ILists
|
||||
public PropertyInfo ItemProperty
|
||||
{
|
||||
get => GetItemProperty();
|
||||
}
|
||||
|
||||
private PropertyInfo m_itemProperty;
|
||||
|
||||
// ========== Methods ==========
|
||||
|
||||
private IEnumerable GetEnumerable()
|
||||
{
|
||||
if (m_enumerable == null && Value != null)
|
||||
{
|
||||
m_enumerable = Value as IEnumerable ?? EnumerateWithReflection();
|
||||
}
|
||||
return m_enumerable;
|
||||
}
|
||||
|
||||
private Type GetGenericTypeDef()
|
||||
{
|
||||
if (m_genericTypeDef == null && Value != null)
|
||||
{
|
||||
var type = Value.GetType();
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
m_genericTypeDef = type.GetGenericTypeDefinition();
|
||||
}
|
||||
}
|
||||
return m_genericTypeDef;
|
||||
}
|
||||
|
||||
private MethodInfo GetGenericToArrayMethod()
|
||||
{
|
||||
if (GenericTypeDef == null) return null;
|
||||
|
||||
if (m_genericToArray == null)
|
||||
{
|
||||
m_genericToArray = GenericTypeDef
|
||||
.MakeGenericType(new Type[] { this.EntryType })
|
||||
.GetMethod("ToArray");
|
||||
}
|
||||
return m_genericToArray;
|
||||
}
|
||||
|
||||
private PropertyInfo GetItemProperty()
|
||||
{
|
||||
if (m_itemProperty == null)
|
||||
{
|
||||
m_itemProperty = Value?.GetType().GetProperty("Item");
|
||||
}
|
||||
return m_itemProperty;
|
||||
}
|
||||
|
||||
private IEnumerable EnumerateWithReflection()
|
||||
{
|
||||
if (Value == null) return null;
|
||||
|
||||
#if CPP
|
||||
if (GenericTypeDef == typeof(Il2CppSystem.Collections.Generic.List<>))
|
||||
{
|
||||
return (IEnumerable)CppListToArrayMethod?.Invoke(Value, new object[0]);
|
||||
}
|
||||
else if (GenericTypeDef == typeof(Il2CppSystem.Collections.Generic.HashSet<>))
|
||||
{
|
||||
return CppHashSetToMono();
|
||||
}
|
||||
else
|
||||
{
|
||||
return CppIListToMono();
|
||||
}
|
||||
#else
|
||||
return Value as IEnumerable;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CPP
|
||||
private IEnumerable CppHashSetToMono()
|
||||
{
|
||||
var set = new HashSet<object>();
|
||||
|
||||
// invoke GetEnumerator
|
||||
var enumerator = Value.GetType().GetMethod("GetEnumerator").Invoke(Value, null);
|
||||
// get the type of it
|
||||
var enumeratorType = enumerator.GetType();
|
||||
// reflect MoveNext and Current
|
||||
var moveNext = enumeratorType.GetMethod("MoveNext");
|
||||
var current = enumeratorType.GetProperty("Current");
|
||||
// iterate
|
||||
while ((bool)moveNext.Invoke(enumerator, null))
|
||||
{
|
||||
set.Add(current.GetValue(enumerator));
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
private IList CppIListToMono()
|
||||
{
|
||||
try
|
||||
{
|
||||
var genericType = typeof(List<>).MakeGenericType(new Type[] { this.EntryType });
|
||||
var list = (IList)Activator.CreateInstance(genericType);
|
||||
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var itm = ItemProperty.GetValue(Value, new object[] { i });
|
||||
list.Add(itm);
|
||||
}
|
||||
catch { break; }
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log("Exception converting Il2Cpp IList to Mono IList: " + e.GetType() + ", " + e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private Type GetEntryType()
|
||||
{
|
||||
if (m_entryType == null)
|
||||
{
|
||||
if (this.MemInfo != null)
|
||||
{
|
||||
Type memberType = null;
|
||||
switch (this.MemInfo.MemberType)
|
||||
{
|
||||
case MemberTypes.Field:
|
||||
memberType = (MemInfo as FieldInfo).FieldType;
|
||||
break;
|
||||
case MemberTypes.Property:
|
||||
memberType = (MemInfo as PropertyInfo).PropertyType;
|
||||
break;
|
||||
}
|
||||
|
||||
if (memberType != null && memberType.IsGenericType)
|
||||
{
|
||||
m_entryType = memberType.GetGenericArguments()[0];
|
||||
}
|
||||
}
|
||||
else if (Value != null)
|
||||
{
|
||||
var type = Value.GetType();
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
m_entryType = type.GetGenericArguments()[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IList probably won't be able to get any EntryType.
|
||||
if (m_entryType == null)
|
||||
{
|
||||
m_entryType = typeof(object);
|
||||
}
|
||||
|
||||
return m_entryType;
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
if (Value == null || Enumerable == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var enumerator = Enumerable.GetEnumerator();
|
||||
if (enumerator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var list = new List<CacheObjectBase>();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
var obj = enumerator.Current;
|
||||
|
||||
if (obj != null && ReflectionHelpers.GetActualType(obj) is Type t)
|
||||
{
|
||||
#if CPP
|
||||
if (obj is Il2CppSystem.Object iObj)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cast = iObj.Il2CppCast(t);
|
||||
if (cast != null)
|
||||
{
|
||||
obj = cast;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endif
|
||||
|
||||
if (CacheFactory.GetCacheObject(obj, t) is CacheObjectBase cached)
|
||||
{
|
||||
list.Add(cached);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(null);
|
||||
}
|
||||
}
|
||||
|
||||
m_cachedEntries = list.ToArray();
|
||||
}
|
||||
|
||||
// ============= GUI Draw =============
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (m_cachedEntries == null)
|
||||
{
|
||||
GUILayout.Label("m_cachedEntries is null!", new GUILayoutOption[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
int count = m_cachedEntries.Length;
|
||||
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
var negativeWhitespace = window.width - (whitespace + 100f);
|
||||
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
string btnLabel = $"[{count}] <color=#2df7b2>{EntryType.FullName}</color>";
|
||||
if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.Width(negativeWhitespace) }))
|
||||
{
|
||||
WindowManager.InspectObject(Value, out bool _);
|
||||
}
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
GUIUnstrip.Space(5);
|
||||
|
||||
if (IsExpanded)
|
||||
{
|
||||
Pages.ItemCount = count;
|
||||
|
||||
if (count > Pages.ItemsPerPage)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUIUnstrip.Space(whitespace);
|
||||
|
||||
Pages.CurrentPageLabel();
|
||||
|
||||
// prev/next page buttons
|
||||
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||
{
|
||||
Pages.TurnPage(Turn.Left);
|
||||
}
|
||||
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||
{
|
||||
Pages.TurnPage(Turn.Right);
|
||||
}
|
||||
|
||||
Pages.DrawLimitInputArea();
|
||||
|
||||
GUIUnstrip.Space(5);
|
||||
}
|
||||
|
||||
int offset = Pages.CalculateOffsetIndex();
|
||||
|
||||
for (int i = offset; i < offset + Pages.ItemsPerPage && i < count; i++)
|
||||
{
|
||||
var entry = m_cachedEntries[i];
|
||||
|
||||
//collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUIUnstrip.Space(whitespace);
|
||||
|
||||
if (entry == null || entry.Value == null)
|
||||
{
|
||||
GUILayout.Label($"[{i}] <i><color=grey>(null)</color></i>", new GUILayoutOption[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
entry.DrawValue(window, window.width - (whitespace + 85));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheMethod : CacheObjectBase
|
||||
{
|
||||
private CacheObjectBase m_cachedReturnValue;
|
||||
|
||||
public override bool HasParameters => base.HasParameters || GenericArgs.Length > 0;
|
||||
|
||||
public Type[] GenericArgs { get; private set; }
|
||||
public Type[][] GenericConstraints { get; private set; }
|
||||
|
||||
public string[] GenericArgInput = new string[0];
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
var mi = (MemInfo as MethodInfo);
|
||||
GenericArgs = mi.GetGenericArguments();
|
||||
|
||||
GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints())
|
||||
.ToArray();
|
||||
|
||||
GenericArgInput = new string[GenericArgs.Length];
|
||||
|
||||
ValueType = mi.ReturnType;
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
//base.UpdateValue();
|
||||
}
|
||||
|
||||
public void Evaluate()
|
||||
{
|
||||
MethodInfo mi;
|
||||
if (GenericArgs.Length > 0)
|
||||
{
|
||||
mi = MakeGenericMethodFromInput();
|
||||
if (mi == null) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
mi = MemInfo as MethodInfo;
|
||||
}
|
||||
|
||||
object ret = null;
|
||||
|
||||
try
|
||||
{
|
||||
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
||||
m_evaluated = true;
|
||||
m_isEvaluating = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
}
|
||||
|
||||
if (ret != null)
|
||||
{
|
||||
m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
|
||||
m_cachedReturnValue.UpdateValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cachedReturnValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
private MethodInfo MakeGenericMethodFromInput()
|
||||
{
|
||||
var mi = MemInfo as MethodInfo;
|
||||
|
||||
var list = new List<Type>();
|
||||
for (int i = 0; i < GenericArgs.Length; i++)
|
||||
{
|
||||
var input = GenericArgInput[i];
|
||||
if (ReflectionHelpers.GetTypeByName(input) is Type t)
|
||||
{
|
||||
if (GenericConstraints[i].Length == 0)
|
||||
{
|
||||
list.Add(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var constraint in GenericConstraints[i].Where(x => x != null))
|
||||
{
|
||||
if (!constraint.IsAssignableFrom(t))
|
||||
{
|
||||
ExplorerCore.LogWarning($"Generic argument #{i}, '{input}' is not assignable from the constraint '{constraint}'!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
list.Add(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
|
||||
$" Make sure you use the full name, including the NameSpace.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// make into a generic with type list
|
||||
mi = mi.MakeGenericMethod(list.ToArray());
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
// ==== GUI DRAW ====
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
string typeLabel = $"<color={UIStyles.Syntax.Class_Instance}>{ValueType.FullName}</color>";
|
||||
|
||||
if (m_evaluated)
|
||||
{
|
||||
if (m_cachedReturnValue != null)
|
||||
{
|
||||
m_cachedReturnValue.DrawValue(window, width);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label($"null ({typeLabel})", new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> ({typeLabel})", new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheOther : CacheObjectBase
|
||||
{
|
||||
public string ButtonLabel => m_btnLabel ?? GetButtonLabel();
|
||||
private string m_btnLabel;
|
||||
|
||||
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
||||
private MethodInfo m_toStringMethod;
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
GetButtonLabel();
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
if (GUILayout.Button(ButtonLabel, new GUILayoutOption[] { GUILayout.Width(width - 15) }))
|
||||
{
|
||||
WindowManager.InspectObject(Value, out bool _);
|
||||
}
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||
}
|
||||
|
||||
private MethodInfo GetToStringMethod()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_toStringMethod = ReflectionHelpers.GetActualType(Value).GetMethod("ToString", new Type[0])
|
||||
?? typeof(object).GetMethod("ToString", new Type[0]);
|
||||
|
||||
// test invoke
|
||||
m_toStringMethod.Invoke(Value, null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
|
||||
}
|
||||
return m_toStringMethod;
|
||||
}
|
||||
|
||||
private string GetButtonLabel()
|
||||
{
|
||||
if (Value == null) return null;
|
||||
|
||||
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
||||
|
||||
var classColor = ValueType.IsAbstract && ValueType.IsSealed
|
||||
? UIStyles.Syntax.Class_Static
|
||||
: UIStyles.Syntax.Class_Instance;
|
||||
|
||||
string typeLabel = $"<color={classColor}>{ValueType.FullName}</color>";
|
||||
|
||||
if (Value is UnityEngine.Object)
|
||||
{
|
||||
label = label.Replace($"({ValueType.FullName})", $"({typeLabel})");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!label.Contains(ValueType.FullName))
|
||||
{
|
||||
label += $" ({typeLabel})";
|
||||
}
|
||||
else
|
||||
{
|
||||
label = label.Replace(ValueType.FullName, typeLabel);
|
||||
}
|
||||
}
|
||||
|
||||
return m_btnLabel = label;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheColor : CacheObjectBase, IExpandHeight
|
||||
{
|
||||
private string r = "0";
|
||||
private string g = "0";
|
||||
private string b = "0";
|
||||
private string a = "0";
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
if (Value == null) return;
|
||||
|
||||
var color = (Color)Value;
|
||||
|
||||
r = color.r.ToString();
|
||||
g = color.g.ToString();
|
||||
b = color.b.ToString();
|
||||
a = color.a.ToString();
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var c = (Color)Value;
|
||||
//GUI.color = c;
|
||||
GUILayout.Label($"<color=#2df7b2>Color:</color> {((Color)Value).ToString()}", new GUILayoutOption[0]);
|
||||
//GUI.color = Color.white;
|
||||
|
||||
if (CanWrite && IsExpanded)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("R:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
r = GUIUnstrip.TextField(r, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("G:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
g = GUIUnstrip.TextField(g, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("B:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
b = GUIUnstrip.TextField(b, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("A:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
a = GUIUnstrip.TextField(a, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw set value button
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
|
||||
{
|
||||
SetValueFromInput();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValueFromInput()
|
||||
{
|
||||
if (float.TryParse(r, out float fR)
|
||||
&& float.TryParse(g, out float fG)
|
||||
&& float.TryParse(b, out float fB)
|
||||
&& float.TryParse(a, out float fA))
|
||||
{
|
||||
Value = new Color(fR, fG, fB, fA);
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheEnum : CacheObjectBase
|
||||
{
|
||||
// public Type EnumType;
|
||||
public string[] EnumNames = new string[0];
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
if (ValueType == null && Value != null)
|
||||
{
|
||||
ValueType = Value.GetType();
|
||||
}
|
||||
|
||||
if (ValueType != null)
|
||||
{
|
||||
// using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags)
|
||||
var values = Enum.GetValues(ValueType);
|
||||
|
||||
var list = new List<string>();
|
||||
foreach (var value in values)
|
||||
{
|
||||
var v = value.ToString();
|
||||
if (list.Contains(v)) continue;
|
||||
list.Add(v);
|
||||
}
|
||||
|
||||
EnumNames = list.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
ReflectionException = "Unknown, could not get Enum names.";
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
if (GUILayout.Button("<", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
SetEnum(-1);
|
||||
SetValue();
|
||||
}
|
||||
if (GUILayout.Button(">", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
SetEnum(1);
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label(Value.ToString() + $"<color={UIStyles.Syntax.StructGreen}><i> ({ValueType})</i></color>", new GUILayoutOption[0]);
|
||||
}
|
||||
|
||||
public void SetEnum(int change)
|
||||
{
|
||||
var names = EnumNames.ToList();
|
||||
|
||||
int newindex = names.IndexOf(Value.ToString()) + change;
|
||||
|
||||
if (newindex >= 0 && newindex < names.Count)
|
||||
{
|
||||
Value = Enum.Parse(ValueType, EnumNames[newindex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheEnumFlags : CacheEnum, IExpandHeight
|
||||
{
|
||||
public bool[] m_enabledFlags = new bool[0];
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
if (Value == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
var enabledNames = Value.ToString().Split(',').Select(it => it.Trim());
|
||||
|
||||
m_enabledFlags = new bool[EnumNames.Length];
|
||||
|
||||
for (int i = 0; i < EnumNames.Length; i++)
|
||||
{
|
||||
m_enabledFlags[i] = enabledNames.Contains(EnumNames[i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label(Value.ToString() + "<color=#2df7b2><i> (" + ValueType + ")</i></color>", new GUILayoutOption[0]);
|
||||
|
||||
if (IsExpanded)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
for (int i = 0; i < EnumNames.Length; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
|
||||
m_enabledFlags[i] = GUILayout.Toggle(m_enabledFlags[i], EnumNames[i], new GUILayoutOption[0]);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
|
||||
{
|
||||
SetFlagsFromInput();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFlagsFromInput()
|
||||
{
|
||||
string val = "";
|
||||
for (int i = 0; i < EnumNames.Length; i++)
|
||||
{
|
||||
if (m_enabledFlags[i])
|
||||
{
|
||||
if (val != "") val += ", ";
|
||||
val += EnumNames[i];
|
||||
}
|
||||
}
|
||||
Value = Enum.Parse(ValueType, val);
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
#if CPP
|
||||
using UnhollowerRuntimeLib;
|
||||
#endif
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CachePrimitive : CacheObjectBase
|
||||
{
|
||||
private string m_valueToString;
|
||||
private bool m_isBool;
|
||||
private bool m_isString;
|
||||
|
||||
public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }));
|
||||
private MethodInfo m_parseMethod;
|
||||
|
||||
private bool m_canBitwiseOperate;
|
||||
private bool m_inBitwiseMode;
|
||||
private string m_bitwiseOperatorInput = "0";
|
||||
private string m_binaryInput;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
if (ValueType == null)
|
||||
{
|
||||
ValueType = Value?.GetType();
|
||||
|
||||
// has to be a string at this point
|
||||
if (ValueType == null)
|
||||
{
|
||||
ValueType = typeof(string);
|
||||
}
|
||||
}
|
||||
|
||||
if (ValueType == typeof(string))
|
||||
{
|
||||
m_isString = true;
|
||||
}
|
||||
else if (ValueType == typeof(bool))
|
||||
{
|
||||
m_isBool = true;
|
||||
}
|
||||
|
||||
m_canBitwiseOperate = typeof(int).IsAssignableFrom(ValueType);
|
||||
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
RefreshToString();
|
||||
}
|
||||
|
||||
private void RefreshToString()
|
||||
{
|
||||
m_valueToString = Value?.ToString();
|
||||
|
||||
if (m_canBitwiseOperate)
|
||||
{
|
||||
var _int = (int)Value;
|
||||
m_binaryInput = Convert.ToString(_int, toBase: 2);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (m_isBool)
|
||||
{
|
||||
var b = (bool)Value;
|
||||
var label = $"<color={(b ? "lime" : "red")}>{b}</color>";
|
||||
|
||||
if (CanWrite)
|
||||
{
|
||||
b = GUILayout.Toggle(b, label, new GUILayoutOption[0]);
|
||||
if (b != (bool)Value)
|
||||
{
|
||||
Value = b;
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label(label, new GUILayoutOption[0]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// all other non-bool values use TextField
|
||||
|
||||
GUILayout.BeginVertical(new GUILayoutOption[0]);
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUILayout.Label("<color=#2df7b2><i>" + ValueType.Name + "</i></color>", new GUILayoutOption[] { GUILayout.Width(50) });
|
||||
|
||||
m_valueToString = GUIUnstrip.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
|
||||
if (CanWrite)
|
||||
{
|
||||
if (GUILayout.Button("<color=#00FF00>Apply</color>", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||
{
|
||||
SetValueFromInput();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_canBitwiseOperate)
|
||||
{
|
||||
m_inBitwiseMode = GUILayout.Toggle(m_inBitwiseMode, "Bitwise?", new GUILayoutOption[0]);
|
||||
}
|
||||
|
||||
GUIUnstrip.Space(10);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (m_inBitwiseMode)
|
||||
{
|
||||
DrawBitwise();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private void DrawBitwise()
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleRight;
|
||||
GUILayout.Label("RHS:", new GUILayoutOption[] { GUILayout.Width(35) });
|
||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||
|
||||
if (GUILayout.Button("~", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
if (int.TryParse(m_bitwiseOperatorInput, out int bit))
|
||||
{
|
||||
Value = ~bit;
|
||||
RefreshToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("<<", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
if (int.TryParse(m_bitwiseOperatorInput, out int bit))
|
||||
{
|
||||
Value = (int)Value << bit;
|
||||
RefreshToString();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(">>", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
if (int.TryParse(m_bitwiseOperatorInput, out int bit))
|
||||
{
|
||||
Value = (int)Value >> bit;
|
||||
RefreshToString();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button("|", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
if (int.TryParse(m_bitwiseOperatorInput, out int bit))
|
||||
{
|
||||
Value = (int)Value | bit;
|
||||
RefreshToString();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button("&", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
if (int.TryParse(m_bitwiseOperatorInput, out int bit))
|
||||
{
|
||||
Value = (int)Value & bit;
|
||||
RefreshToString();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
if (int.TryParse(m_bitwiseOperatorInput, out int bit))
|
||||
{
|
||||
Value = (int)Value ^ bit;
|
||||
RefreshToString();
|
||||
}
|
||||
}
|
||||
|
||||
m_bitwiseOperatorInput = GUIUnstrip.TextField(m_bitwiseOperatorInput, new GUILayoutOption[] { GUILayout.Width(55) });
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUILayout.Label($"<color=cyan>Binary:</color>", new GUILayoutOption[] { GUILayout.Width(60) });
|
||||
m_binaryInput = GUIUnstrip.TextField(m_binaryInput, new GUILayoutOption[0]);
|
||||
if (CanWrite)
|
||||
{
|
||||
if (GUILayout.Button("Apply", new GUILayoutOption[0]))
|
||||
{
|
||||
SetValueFromBinaryInput();
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public void SetValueFromInput()
|
||||
{
|
||||
if (MemInfo == null)
|
||||
{
|
||||
ExplorerCore.Log("Trying to SetValue but the MemberInfo is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isString)
|
||||
{
|
||||
Value = m_valueToString;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Value = ParseMethod.Invoke(null, new object[] { m_valueToString });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log("Exception parsing value: " + e.GetType() + ", " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
SetValue();
|
||||
RefreshToString();
|
||||
}
|
||||
|
||||
private void SetValueFromBinaryInput()
|
||||
{
|
||||
try
|
||||
{
|
||||
var method = typeof(Convert).GetMethod($"To{ValueType.Name}", new Type[] { typeof(string), typeof(int) });
|
||||
Value = method.Invoke(null, new object[] { m_binaryInput, 2 });
|
||||
|
||||
SetValue();
|
||||
RefreshToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log("Exception setting value: " + e.GetType() + ", " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheQuaternion : CacheObjectBase, IExpandHeight
|
||||
{
|
||||
private string x = "0";
|
||||
private string y = "0";
|
||||
private string z = "0";
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
if (Value == null) return;
|
||||
|
||||
var euler = ((Quaternion)Value).eulerAngles;
|
||||
|
||||
x = euler.x.ToString();
|
||||
y = euler.y.ToString();
|
||||
z = euler.z.ToString();
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label($"<color=#2df7b2>Quaternion</color>: {((Quaternion)Value).eulerAngles.ToString()}", new GUILayoutOption[0]);
|
||||
|
||||
if (CanWrite && IsExpanded)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
x = GUIUnstrip.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
y = GUIUnstrip.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
z = GUIUnstrip.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw set value button
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
|
||||
{
|
||||
SetValueFromInput();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValueFromInput()
|
||||
{
|
||||
if (float.TryParse(x, out float fX)
|
||||
&& float.TryParse(y, out float fY)
|
||||
&& float.TryParse(z, out float fZ))
|
||||
{
|
||||
Value = Quaternion.Euler(new Vector3(fX, fY, fZ));
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheRect : CacheObjectBase, IExpandHeight
|
||||
{
|
||||
private string x = "0";
|
||||
private string y = "0";
|
||||
private string w = "0";
|
||||
private string h = "0";
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
if (Value == null) return;
|
||||
|
||||
var rect = (Rect)Value;
|
||||
|
||||
x = rect.x.ToString();
|
||||
y = rect.y.ToString();
|
||||
w = rect.width.ToString();
|
||||
h = rect.height.ToString();
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label($"<color=#2df7b2>Rect</color>: {((Rect)Value).ToString()}", new GUILayoutOption[0]);
|
||||
|
||||
if (CanWrite && IsExpanded)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
x = GUIUnstrip.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
y = GUIUnstrip.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
w = GUIUnstrip.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("H:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
h = GUIUnstrip.TextField(h, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw set value button
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
|
||||
{
|
||||
SetValueFromInput();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValueFromInput()
|
||||
{
|
||||
if (float.TryParse(x, out float fX)
|
||||
&& float.TryParse(y, out float fY)
|
||||
&& float.TryParse(w, out float fW)
|
||||
&& float.TryParse(h, out float fH))
|
||||
{
|
||||
Value = new Rect(fX, fY, fW, fH);
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class CacheVector : CacheObjectBase, IExpandHeight
|
||||
{
|
||||
public int VectorSize = 2;
|
||||
|
||||
private string x = "0";
|
||||
private string y = "0";
|
||||
private string z = "0";
|
||||
private string w = "0";
|
||||
|
||||
private MethodInfo m_toStringMethod;
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
public float WhiteSpace { get; set; } = 215f;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
if (ValueType == null && Value != null)
|
||||
{
|
||||
ValueType = Value.GetType();
|
||||
}
|
||||
|
||||
if (ValueType == typeof(Vector2))
|
||||
{
|
||||
VectorSize = 2;
|
||||
m_toStringMethod = typeof(Vector2).GetMethod("ToString", new Type[0]);
|
||||
}
|
||||
else if (ValueType == typeof(Vector3))
|
||||
{
|
||||
VectorSize = 3;
|
||||
m_toStringMethod = typeof(Vector3).GetMethod("ToString", new Type[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorSize = 4;
|
||||
m_toStringMethod = typeof(Vector4).GetMethod("ToString", new Type[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
|
||||
if (Value is Vector2 vec2)
|
||||
{
|
||||
x = vec2.x.ToString();
|
||||
y = vec2.y.ToString();
|
||||
}
|
||||
else if (Value is Vector3 vec3)
|
||||
{
|
||||
x = vec3.x.ToString();
|
||||
y = vec3.y.ToString();
|
||||
z = vec3.z.ToString();
|
||||
}
|
||||
else if (Value is Vector4 vec4)
|
||||
{
|
||||
x = vec4.x.ToString();
|
||||
y = vec4.y.ToString();
|
||||
z = vec4.z.ToString();
|
||||
w = vec4.w.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawValue(Rect window, float width)
|
||||
{
|
||||
if (CanWrite)
|
||||
{
|
||||
if (!IsExpanded)
|
||||
{
|
||||
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
|
||||
{
|
||||
IsExpanded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label($"<color=#2df7b2>Vector{VectorSize}</color>: {(string)m_toStringMethod.Invoke(Value, new object[0])}", new GUILayoutOption[0]);
|
||||
|
||||
if (CanWrite && IsExpanded)
|
||||
{
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var whitespace = CalcWhitespace(window);
|
||||
|
||||
// always draw x and y
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
x = GUIUnstrip.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
y = GUIUnstrip.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (VectorSize > 2)
|
||||
{
|
||||
// draw z
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
z = GUIUnstrip.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
if (VectorSize > 3)
|
||||
{
|
||||
// draw w
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||
w = GUIUnstrip.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) });
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
// draw set value button
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
GUIUnstrip.Space(whitespace);
|
||||
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
|
||||
{
|
||||
SetValueFromInput();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValueFromInput()
|
||||
{
|
||||
if (float.TryParse(x, out float fX)
|
||||
&& float.TryParse(y, out float fY)
|
||||
&& float.TryParse(z, out float fZ)
|
||||
&& float.TryParse(w, out float fW))
|
||||
{
|
||||
object vector = null;
|
||||
|
||||
switch (VectorSize)
|
||||
{
|
||||
case 2: vector = new Vector2(fX, fY); break;
|
||||
case 3: vector = new Vector3(fX, fY, fZ); break;
|
||||
case 4: vector = new Vector4(fX, fY, fZ, fW); break;
|
||||
}
|
||||
|
||||
if (vector != null)
|
||||
{
|
||||
Value = vector;
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class ModConfig
|
||||
{
|
||||
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
|
||||
|
||||
[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\Explorer";
|
||||
[XmlIgnore] private const string SETTINGS_PATH = EXPLORER_FOLDER + @"\config.xml";
|
||||
|
||||
[XmlIgnore] public static ModConfig Instance;
|
||||
|
||||
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
public Vector2 Default_Window_Size = new Vector2(550, 700);
|
||||
public int Default_Page_Limit = 20;
|
||||
|
||||
public static void OnLoad()
|
||||
{
|
||||
if (!Directory.Exists(EXPLORER_FOLDER))
|
||||
{
|
||||
Directory.CreateDirectory(EXPLORER_FOLDER);
|
||||
}
|
||||
|
||||
if (LoadSettings()) return;
|
||||
|
||||
Instance = new ModConfig();
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
// returns true if settings successfully loaded
|
||||
public static bool LoadSettings()
|
||||
{
|
||||
if (!File.Exists(SETTINGS_PATH))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
using (var file = File.OpenRead(SETTINGS_PATH))
|
||||
{
|
||||
Instance = (ModConfig)Serializer.Deserialize(file);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Instance != null;
|
||||
}
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
if (File.Exists(SETTINGS_PATH))
|
||||
File.Delete(SETTINGS_PATH);
|
||||
|
||||
using (var file = File.Create(SETTINGS_PATH))
|
||||
{
|
||||
Serializer.Serialize(file, Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
src/Core/CSharp/DummyBehaviour.cs
Normal file
29
src/Core/CSharp/DummyBehaviour.cs
Normal file
@ -0,0 +1,29 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public class DummyBehaviour : MonoBehaviour
|
||||
{
|
||||
public static DummyBehaviour Instance;
|
||||
|
||||
public static void Setup()
|
||||
{
|
||||
var obj = new GameObject("Explorer_DummyBehaviour");
|
||||
DontDestroyOnLoad(obj);
|
||||
obj.hideFlags |= HideFlags.HideAndDontSave;
|
||||
|
||||
obj.AddComponent<DummyBehaviour>();
|
||||
}
|
||||
|
||||
internal void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
76
src/Core/CSharp/ScriptEvaluator.cs
Normal file
76
src/Core/CSharp/ScriptEvaluator.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Mono.CSharp;
|
||||
|
||||
// Thanks to ManlyMarco for most of this
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public class ScriptEvaluator : Evaluator, IDisposable
|
||||
{
|
||||
private static readonly HashSet<string> StdLib = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
|
||||
{
|
||||
"mscorlib", "System.Core", "System", "System.Xml"
|
||||
};
|
||||
|
||||
internal static TextWriter _textWriter;
|
||||
internal static StreamReportPrinter _reportPrinter;
|
||||
|
||||
public ScriptEvaluator(TextWriter tw) : base(BuildContext(tw))
|
||||
{
|
||||
_textWriter = tw;
|
||||
|
||||
ImportAppdomainAssemblies(ReferenceAssembly);
|
||||
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
|
||||
_textWriter.Dispose();
|
||||
}
|
||||
|
||||
private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
|
||||
{
|
||||
string name = args.LoadedAssembly.GetName().Name;
|
||||
|
||||
if (StdLib.Contains(name))
|
||||
return;
|
||||
|
||||
ReferenceAssembly(args.LoadedAssembly);
|
||||
}
|
||||
|
||||
private static CompilerContext BuildContext(TextWriter tw)
|
||||
{
|
||||
_reportPrinter = new StreamReportPrinter(tw);
|
||||
|
||||
var settings = new CompilerSettings
|
||||
{
|
||||
Version = LanguageVersion.Experimental,
|
||||
GenerateDebugInfo = false,
|
||||
StdLib = true,
|
||||
Target = Target.Library,
|
||||
WarningLevel = 0,
|
||||
EnhancedWarnings = false
|
||||
};
|
||||
|
||||
return new CompilerContext(settings, _reportPrinter);
|
||||
}
|
||||
|
||||
private static void ImportAppdomainAssemblies(Action<Assembly> import)
|
||||
{
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
string name = assembly.GetName().Name;
|
||||
if (StdLib.Contains(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
import(assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
68
src/Core/CSharp/ScriptInteraction.cs
Normal file
68
src/Core/CSharp/ScriptInteraction.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Mono.CSharp;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public class ScriptInteraction : InteractiveBase
|
||||
{
|
||||
public static void Log(object message)
|
||||
{
|
||||
ExplorerCore.Log(message);
|
||||
}
|
||||
|
||||
public static void StartCoroutine(IEnumerator ienumerator)
|
||||
{
|
||||
RuntimeProvider.Instance.StartConsoleCoroutine(ienumerator);
|
||||
}
|
||||
|
||||
public static void AddUsing(string directive)
|
||||
{
|
||||
CSharpConsole.Instance.AddUsing(directive);
|
||||
}
|
||||
|
||||
public static void GetUsing()
|
||||
{
|
||||
ExplorerCore.Log(CSharpConsole.Instance.Evaluator.GetUsing());
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
CSharpConsole.Instance.ResetConsole();
|
||||
}
|
||||
|
||||
public static object CurrentTarget()
|
||||
{
|
||||
return InspectorManager.Instance?.m_activeInspector?.Target;
|
||||
}
|
||||
|
||||
public static object[] AllTargets()
|
||||
{
|
||||
int count = InspectorManager.Instance?.m_currentInspectors.Count ?? 0;
|
||||
object[] ret = new object[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
ret[i] = InspectorManager.Instance?.m_currentInspectors[i].Target;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void Inspect(object obj)
|
||||
{
|
||||
InspectorManager.Instance.Inspect(obj);
|
||||
}
|
||||
|
||||
public static void Inspect(Type type)
|
||||
{
|
||||
InspectorManager.Instance.Inspect(type);
|
||||
}
|
||||
}
|
||||
}
|
71
src/Core/CSharp/Suggestion.cs
Normal file
71
src/Core/CSharp/Suggestion.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public struct Suggestion
|
||||
{
|
||||
public enum Contexts
|
||||
{
|
||||
Namespace,
|
||||
Keyword,
|
||||
Other
|
||||
}
|
||||
|
||||
// ~~~~ Instance ~~~~
|
||||
|
||||
public readonly string Prefix;
|
||||
public readonly string Addition;
|
||||
public readonly Contexts Context;
|
||||
|
||||
public string Full => Prefix + Addition;
|
||||
|
||||
public Color TextColor => GetTextColor();
|
||||
|
||||
public Suggestion(string addition, string prefix, Contexts type)
|
||||
{
|
||||
Addition = addition;
|
||||
Prefix = prefix;
|
||||
Context = type;
|
||||
}
|
||||
|
||||
private Color GetTextColor()
|
||||
{
|
||||
switch (Context)
|
||||
{
|
||||
case Contexts.Namespace: return Color.grey;
|
||||
case Contexts.Keyword: return keywordColor;
|
||||
default: return Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
// ~~~~ Static ~~~~
|
||||
|
||||
public static HashSet<string> Namespaces => m_namspaces ?? GetNamespaces();
|
||||
private static HashSet<string> m_namspaces;
|
||||
|
||||
public static HashSet<string> Keywords => m_keywords ?? (m_keywords = new HashSet<string>(CSLexerHighlighter.validKeywordMatcher.Keywords));
|
||||
private static HashSet<string> m_keywords;
|
||||
|
||||
private static readonly Color keywordColor = new Color(80f / 255f, 150f / 255f, 215f / 255f);
|
||||
|
||||
private static HashSet<string> GetNamespaces()
|
||||
{
|
||||
HashSet<string> set = new HashSet<string>(
|
||||
AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(GetTypes)
|
||||
.Where(x => x.IsPublic && !string.IsNullOrEmpty(x.Namespace))
|
||||
.Select(x => x.Namespace));
|
||||
|
||||
return m_namspaces = set;
|
||||
|
||||
IEnumerable<Type> GetTypes(Assembly asm) => asm.TryGetTypes();
|
||||
}
|
||||
}
|
||||
}
|
205
src/Core/Config/ExplorerConfig.cs
Normal file
205
src/Core/Config/ExplorerConfig.cs
Normal file
@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using IniParser;
|
||||
using IniParser.Parser;
|
||||
using UnityExplorer.UI;
|
||||
using System.Globalization;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.UI.Main;
|
||||
|
||||
namespace UnityExplorer.Core.Config
|
||||
{
|
||||
public class ExplorerConfig
|
||||
{
|
||||
public static ExplorerConfig Instance;
|
||||
|
||||
internal static readonly IniDataParser _parser = new IniDataParser();
|
||||
internal static readonly string INI_PATH = Path.Combine(ExplorerCore.Loader.ConfigFolder, "config.ini");
|
||||
|
||||
internal static CultureInfo _enCulture = new CultureInfo("en-US");
|
||||
|
||||
// Actual configs
|
||||
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
public bool Force_Unlock_Mouse = true;
|
||||
public int Default_Page_Limit = 25;
|
||||
public string Default_Output_Path = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "Output");
|
||||
public bool Log_Unity_Debug = false;
|
||||
public bool Hide_On_Startup = false;
|
||||
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
public int Active_Tab = 0;
|
||||
public bool DebugConsole_Hidden = false;
|
||||
public bool SceneExplorer_Hidden = false;
|
||||
|
||||
private const string DEFAULT_WINDOW_ANCHORS = "0.25,0.10,0.78,0.95";
|
||||
|
||||
public static event Action OnConfigChanged;
|
||||
|
||||
internal static void InvokeConfigChanged()
|
||||
{
|
||||
OnConfigChanged?.Invoke();
|
||||
}
|
||||
|
||||
public static void OnLoad()
|
||||
{
|
||||
Instance = new ExplorerConfig();
|
||||
_parser.Configuration.CommentString = "#";
|
||||
|
||||
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
|
||||
SceneExplorer.OnToggleShow += SceneExplorer_OnToggleShow;
|
||||
DebugConsole.OnToggleShow += DebugConsole_OnToggleShow;
|
||||
MainMenu.OnActiveTabChanged += MainMenu_OnActiveTabChanged;
|
||||
|
||||
if (LoadSettings())
|
||||
return;
|
||||
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
public static bool LoadSettings()
|
||||
{
|
||||
if (!File.Exists(INI_PATH))
|
||||
return false;
|
||||
|
||||
string ini = File.ReadAllText(INI_PATH);
|
||||
|
||||
var data = _parser.Parse(ini);
|
||||
|
||||
foreach (var config in data.Sections["Config"])
|
||||
{
|
||||
switch (config.KeyName)
|
||||
{
|
||||
case nameof(Main_Menu_Toggle):
|
||||
Instance.Main_Menu_Toggle = (KeyCode)Enum.Parse(typeof(KeyCode), config.Value);
|
||||
break;
|
||||
case nameof(Force_Unlock_Mouse):
|
||||
Instance.Force_Unlock_Mouse = bool.Parse(config.Value);
|
||||
break;
|
||||
case nameof(Default_Page_Limit):
|
||||
Instance.Default_Page_Limit = int.Parse(config.Value);
|
||||
break;
|
||||
case nameof(Log_Unity_Debug):
|
||||
Instance.Log_Unity_Debug = bool.Parse(config.Value);
|
||||
break;
|
||||
case nameof(Default_Output_Path):
|
||||
Instance.Default_Output_Path = config.Value;
|
||||
break;
|
||||
case nameof(Hide_On_Startup):
|
||||
Instance.Hide_On_Startup = bool.Parse(config.Value);
|
||||
break;
|
||||
case nameof(Window_Anchors):
|
||||
Instance.Window_Anchors = config.Value;
|
||||
break;
|
||||
case nameof(Active_Tab):
|
||||
Instance.Active_Tab = int.Parse(config.Value);
|
||||
break;
|
||||
case nameof(DebugConsole_Hidden):
|
||||
Instance.DebugConsole_Hidden = bool.Parse(config.Value);
|
||||
break;
|
||||
case nameof(SceneExplorer_Hidden):
|
||||
Instance.SceneExplorer_Hidden = bool.Parse(config.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
var data = new IniParser.Model.IniData();
|
||||
|
||||
data.Sections.AddSection("Config");
|
||||
|
||||
var sec = data.Sections["Config"];
|
||||
sec.AddKey(nameof(Main_Menu_Toggle), Instance.Main_Menu_Toggle.ToString());
|
||||
sec.AddKey(nameof(Force_Unlock_Mouse), Instance.Force_Unlock_Mouse.ToString());
|
||||
sec.AddKey(nameof(Default_Page_Limit), Instance.Default_Page_Limit.ToString());
|
||||
sec.AddKey(nameof(Log_Unity_Debug), Instance.Log_Unity_Debug.ToString());
|
||||
sec.AddKey(nameof(Default_Output_Path), Instance.Default_Output_Path);
|
||||
sec.AddKey(nameof(Hide_On_Startup), Instance.Hide_On_Startup.ToString());
|
||||
sec.AddKey(nameof(Window_Anchors), GetWindowAnchorsString());
|
||||
sec.AddKey(nameof(Active_Tab), Instance.Active_Tab.ToString());
|
||||
sec.AddKey(nameof(DebugConsole_Hidden), Instance.DebugConsole_Hidden.ToString());
|
||||
sec.AddKey(nameof(SceneExplorer_Hidden), Instance.SceneExplorer_Hidden.ToString());
|
||||
|
||||
if (!Directory.Exists(ExplorerCore.Loader.ConfigFolder))
|
||||
Directory.CreateDirectory(ExplorerCore.Loader.ConfigFolder);
|
||||
|
||||
File.WriteAllText(INI_PATH, data.ToString());
|
||||
}
|
||||
|
||||
private static void SceneExplorer_OnToggleShow()
|
||||
{
|
||||
Instance.SceneExplorer_Hidden = SceneExplorer.UI.Hiding;
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
private static void DebugConsole_OnToggleShow()
|
||||
{
|
||||
Instance.DebugConsole_Hidden = DebugConsole.Hiding;
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
private static void MainMenu_OnActiveTabChanged(int page)
|
||||
{
|
||||
Instance.Active_Tab = page;
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
// ============ Window Anchors specific stuff ============== //
|
||||
|
||||
private static void PanelDragger_OnFinishResize()
|
||||
{
|
||||
Instance.Window_Anchors = GetWindowAnchorsString();
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
internal Vector4 GetWindowAnchorsVector()
|
||||
{
|
||||
try
|
||||
{
|
||||
var split = Window_Anchors.Split(',');
|
||||
|
||||
if (split.Length != 4)
|
||||
throw new Exception();
|
||||
|
||||
Vector4 ret = Vector4.zero;
|
||||
ret.x = float.Parse(split[0], _enCulture);
|
||||
ret.y = float.Parse(split[1], _enCulture);
|
||||
ret.z = float.Parse(split[2], _enCulture);
|
||||
ret.w = float.Parse(split[3], _enCulture);
|
||||
return ret;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DefaultWindowAnchors();
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetWindowAnchorsString()
|
||||
{
|
||||
try
|
||||
{
|
||||
var rect = PanelDragger.Instance.Panel;
|
||||
return string.Format(_enCulture, "{0},{1},{2},{3}", new object[]
|
||||
{
|
||||
rect.anchorMin.x,
|
||||
rect.anchorMin.y,
|
||||
rect.anchorMax.x,
|
||||
rect.anchorMax.y
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DEFAULT_WINDOW_ANCHORS;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Vector4 DefaultWindowAnchors()
|
||||
{
|
||||
Instance.Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
return new Vector4(0.25f, 0.1f, 0.78f, 0.95f);
|
||||
}
|
||||
}
|
||||
}
|
23
src/Core/Input/IHandleInput.cs
Normal file
23
src/Core/Input/IHandleInput.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public interface IHandleInput
|
||||
{
|
||||
Vector2 MousePosition { get; }
|
||||
|
||||
bool GetKeyDown(KeyCode key);
|
||||
bool GetKey(KeyCode key);
|
||||
|
||||
bool GetMouseButtonDown(int btn);
|
||||
bool GetMouseButton(int btn);
|
||||
|
||||
BaseInputModule UIModule { get; }
|
||||
|
||||
PointerEventData InputPointerEvent { get; }
|
||||
|
||||
void AddUIInputModule();
|
||||
void ActivateModule();
|
||||
}
|
||||
}
|
61
src/Core/Input/InputManager.cs
Normal file
61
src/Core/Input/InputManager.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public enum InputType
|
||||
{
|
||||
InputSystem,
|
||||
Legacy,
|
||||
None
|
||||
}
|
||||
|
||||
public static class InputManager
|
||||
{
|
||||
public static InputType CurrentType { get; private set; }
|
||||
|
||||
private static IHandleInput m_inputModule;
|
||||
|
||||
public static Vector3 MousePosition => m_inputModule.MousePosition;
|
||||
|
||||
public static bool GetKeyDown(KeyCode key) => m_inputModule.GetKeyDown(key);
|
||||
public static bool GetKey(KeyCode key) => m_inputModule.GetKey(key);
|
||||
|
||||
public static bool GetMouseButtonDown(int btn) => m_inputModule.GetMouseButtonDown(btn);
|
||||
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
|
||||
|
||||
public static BaseInputModule UIInput => m_inputModule.UIModule;
|
||||
public static PointerEventData InputPointerEvent => m_inputModule.InputPointerEvent;
|
||||
|
||||
public static void ActivateUIModule() => m_inputModule.ActivateModule();
|
||||
|
||||
public static void AddUIModule()
|
||||
{
|
||||
m_inputModule.AddUIInputModule();
|
||||
ActivateUIModule();
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
||||
{
|
||||
m_inputModule = new InputSystem();
|
||||
CurrentType = InputType.InputSystem;
|
||||
}
|
||||
else if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
|
||||
{
|
||||
m_inputModule = new LegacyInput();
|
||||
CurrentType = InputType.Legacy;
|
||||
}
|
||||
|
||||
if (m_inputModule == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find any Input module!");
|
||||
m_inputModule = new NoInput();
|
||||
CurrentType = InputType.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
171
src/Core/Input/InputSystem.cs
Normal file
171
src/Core/Input/InputSystem.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public class InputSystem : IHandleInput
|
||||
{
|
||||
public InputSystem()
|
||||
{
|
||||
ExplorerCore.Log("Initializing new InputSystem support...");
|
||||
|
||||
m_kbCurrentProp = TKeyboard.GetProperty("current");
|
||||
m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey });
|
||||
|
||||
var btnControl = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Controls.ButtonControl");
|
||||
m_btnIsPressedProp = btnControl.GetProperty("isPressed");
|
||||
m_btnWasPressedProp = btnControl.GetProperty("wasPressedThisFrame");
|
||||
|
||||
m_mouseCurrentProp = TMouse.GetProperty("current");
|
||||
m_leftButtonProp = TMouse.GetProperty("leftButton");
|
||||
m_rightButtonProp = TMouse.GetProperty("rightButton");
|
||||
|
||||
m_positionProp = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
||||
.GetProperty("position");
|
||||
|
||||
m_readVector2InputMethod = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
||||
.MakeGenericType(typeof(Vector2))
|
||||
.GetMethod("ReadValue");
|
||||
}
|
||||
|
||||
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||
private static Type m_tKeyboard;
|
||||
|
||||
public static Type TMouse => m_tMouse ?? (m_tMouse = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Mouse"));
|
||||
private static Type m_tMouse;
|
||||
|
||||
public static Type TKey => m_tKey ?? (m_tKey = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Key"));
|
||||
private static Type m_tKey;
|
||||
|
||||
private static PropertyInfo m_btnIsPressedProp;
|
||||
private static PropertyInfo m_btnWasPressedProp;
|
||||
|
||||
private static object CurrentKeyboard => m_currentKeyboard ?? (m_currentKeyboard = m_kbCurrentProp.GetValue(null, null));
|
||||
private static object m_currentKeyboard;
|
||||
private static PropertyInfo m_kbCurrentProp;
|
||||
private static PropertyInfo m_kbIndexer;
|
||||
|
||||
private static object CurrentMouse => m_currentMouse ?? (m_currentMouse = m_mouseCurrentProp.GetValue(null, null));
|
||||
private static object m_currentMouse;
|
||||
private static PropertyInfo m_mouseCurrentProp;
|
||||
|
||||
private static object LeftMouseButton => m_lmb ?? (m_lmb = m_leftButtonProp.GetValue(CurrentMouse, null));
|
||||
private static object m_lmb;
|
||||
private static PropertyInfo m_leftButtonProp;
|
||||
|
||||
private static object RightMouseButton => m_rmb ?? (m_rmb = m_rightButtonProp.GetValue(CurrentMouse, null));
|
||||
private static object m_rmb;
|
||||
private static PropertyInfo m_rightButtonProp;
|
||||
|
||||
private static object MousePositionInfo => m_pos ?? (m_pos = m_positionProp.GetValue(CurrentMouse, null));
|
||||
private static object m_pos;
|
||||
private static PropertyInfo m_positionProp;
|
||||
private static MethodInfo m_readVector2InputMethod;
|
||||
|
||||
public Vector2 MousePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Vector2)m_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static Dictionary<KeyCode, object> ActualKeyDict = new Dictionary<KeyCode, object>();
|
||||
|
||||
internal object GetActualKey(KeyCode key)
|
||||
{
|
||||
if (!ActualKeyDict.ContainsKey(key))
|
||||
{
|
||||
var s = key.ToString();
|
||||
if (s.Contains("Control"))
|
||||
s = s.Replace("Control", "Ctrl");
|
||||
else if (s.Contains("Return"))
|
||||
s = "Enter";
|
||||
|
||||
var parsed = Enum.Parse(TKey, s);
|
||||
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
||||
|
||||
ActualKeyDict.Add(key, actualKey);
|
||||
}
|
||||
|
||||
return ActualKeyDict[key];
|
||||
}
|
||||
|
||||
public bool GetKeyDown(KeyCode key) => (bool)m_btnWasPressedProp.GetValue(GetActualKey(key), null);
|
||||
|
||||
public bool GetKey(KeyCode key) => (bool)m_btnIsPressedProp.GetValue(GetActualKey(key), null);
|
||||
|
||||
public bool GetMouseButtonDown(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case 0: return (bool)m_btnWasPressedProp.GetValue(LeftMouseButton, null);
|
||||
case 1: return (bool)m_btnWasPressedProp.GetValue(RightMouseButton, null);
|
||||
// case 2: return (bool)_btnWasPressedProp.GetValue(MiddleMouseButton, null);
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetMouseButton(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case 0: return (bool)m_btnIsPressedProp.GetValue(LeftMouseButton, null);
|
||||
case 1: return (bool)m_btnIsPressedProp.GetValue(RightMouseButton, null);
|
||||
// case 2: return (bool)_btnIsPressedProp.GetValue(MiddleMouseButton, null);
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
// UI Input
|
||||
|
||||
//public Type TInputSystemUIInputModule
|
||||
// => m_tUIInputModule
|
||||
// ?? (m_tUIInputModule = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
|
||||
//internal Type m_tUIInputModule;
|
||||
|
||||
public BaseInputModule UIModule => null; // m_newInputModule;
|
||||
//internal BaseInputModule m_newInputModule;
|
||||
|
||||
public PointerEventData InputPointerEvent => null;
|
||||
|
||||
public void AddUIInputModule()
|
||||
{
|
||||
// if (TInputSystemUIInputModule != null)
|
||||
// {
|
||||
//#if CPP
|
||||
// // m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
|
||||
//#else
|
||||
// m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
|
||||
//#endif
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ExplorerCore.LogWarning("New input system: Could not find type by name 'UnityEngine.InputSystem.UI.InputSystemUIInputModule'");
|
||||
// }
|
||||
}
|
||||
|
||||
public void ActivateModule()
|
||||
{
|
||||
//#if CPP
|
||||
// // m_newInputModule.ActivateModule();
|
||||
//#else
|
||||
// m_newInputModule.ActivateModule();
|
||||
//#endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
64
src/Core/Input/LegacyInput.cs
Normal file
64
src/Core/Input/LegacyInput.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public class LegacyInput : IHandleInput
|
||||
{
|
||||
public LegacyInput()
|
||||
{
|
||||
ExplorerCore.Log("Initializing Legacy Input support...");
|
||||
|
||||
m_mousePositionProp = TInput.GetProperty("mousePosition");
|
||||
m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
|
||||
m_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
|
||||
m_getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
|
||||
m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
|
||||
}
|
||||
|
||||
public static Type TInput => m_tInput ?? (m_tInput = ReflectionUtility.GetTypeByName("UnityEngine.Input"));
|
||||
private static Type m_tInput;
|
||||
|
||||
private static PropertyInfo m_mousePositionProp;
|
||||
private static MethodInfo m_getKeyMethod;
|
||||
private static MethodInfo m_getKeyDownMethod;
|
||||
private static MethodInfo m_getMouseButtonMethod;
|
||||
private static MethodInfo m_getMouseButtonDownMethod;
|
||||
|
||||
public Vector2 MousePosition => (Vector3)m_mousePositionProp.GetValue(null, null);
|
||||
|
||||
public bool GetKey(KeyCode key) => (bool)m_getKeyMethod.Invoke(null, new object[] { key });
|
||||
|
||||
public bool GetKeyDown(KeyCode key) => (bool)m_getKeyDownMethod.Invoke(null, new object[] { key });
|
||||
|
||||
public bool GetMouseButton(int btn) => (bool)m_getMouseButtonMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
public bool GetMouseButtonDown(int btn) => (bool)m_getMouseButtonDownMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
// UI Input module
|
||||
|
||||
public BaseInputModule UIModule => m_inputModule;
|
||||
internal StandaloneInputModule m_inputModule;
|
||||
|
||||
public PointerEventData InputPointerEvent =>
|
||||
#if CPP
|
||||
m_inputModule.m_InputPointerEvent;
|
||||
#else
|
||||
null;
|
||||
#endif
|
||||
|
||||
public void AddUIInputModule()
|
||||
{
|
||||
m_inputModule = UIManager.CanvasRoot.gameObject.AddComponent<StandaloneInputModule>();
|
||||
}
|
||||
|
||||
public void ActivateModule()
|
||||
{
|
||||
m_inputModule.ActivateModule();
|
||||
}
|
||||
}
|
||||
}
|
23
src/Core/Input/NoInput.cs
Normal file
23
src/Core/Input/NoInput.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
// Just a stub for games where no Input module was able to load at all.
|
||||
|
||||
public class NoInput : IHandleInput
|
||||
{
|
||||
public Vector2 MousePosition => Vector2.zero;
|
||||
|
||||
public bool GetKey(KeyCode key) => false;
|
||||
public bool GetKeyDown(KeyCode key) => false;
|
||||
|
||||
public bool GetMouseButton(int btn) => false;
|
||||
public bool GetMouseButtonDown(int btn) => false;
|
||||
|
||||
public BaseInputModule UIModule => null;
|
||||
public PointerEventData InputPointerEvent => null;
|
||||
public void ActivateModule() { }
|
||||
public void AddUIInputModule() { }
|
||||
}
|
||||
}
|
138
src/Core/InspectorManager.cs
Normal file
138
src/Core/InspectorManager.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Inspectors.Reflection;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class InspectorManager
|
||||
{
|
||||
public static InspectorManager Instance { get; private set; }
|
||||
|
||||
internal static InspectorManagerUI UI;
|
||||
|
||||
public InspectorManager()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
UI = new InspectorManagerUI();
|
||||
UI.ConstructInspectorPane();
|
||||
}
|
||||
|
||||
public InspectorBase m_activeInspector;
|
||||
public readonly List<InspectorBase> m_currentInspectors = new List<InspectorBase>();
|
||||
|
||||
public void Update()
|
||||
{
|
||||
for (int i = 0; i < m_currentInspectors.Count; i++)
|
||||
{
|
||||
if (i >= m_currentInspectors.Count)
|
||||
break;
|
||||
|
||||
m_currentInspectors[i].Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void Inspect(object obj, CacheObjectBase parentMember = null)
|
||||
{
|
||||
obj = ReflectionProvider.Instance.Cast(obj, ReflectionProvider.Instance.GetActualType(obj));
|
||||
|
||||
UnityEngine.Object unityObj = obj as UnityEngine.Object;
|
||||
|
||||
if (obj.IsNullOrDestroyed(false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// check if currently inspecting this object
|
||||
foreach (InspectorBase tab in m_currentInspectors)
|
||||
{
|
||||
if (ReferenceEquals(obj, tab.Target))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
#if CPP
|
||||
else if (unityObj && tab.Target is UnityEngine.Object uTabObj)
|
||||
{
|
||||
if (unityObj.m_CachedPtr == uTabObj.m_CachedPtr)
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
InspectorBase inspector;
|
||||
if (obj is GameObject go)
|
||||
inspector = new GameObjectInspector(go);
|
||||
else
|
||||
inspector = new InstanceInspector(obj);
|
||||
|
||||
if (inspector is ReflectionInspector ri)
|
||||
ri.ParentMember = parentMember;
|
||||
|
||||
m_currentInspectors.Add(inspector);
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void Inspect(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("The provided type was null!");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var tab in m_currentInspectors.Where(x => x is StaticInspector))
|
||||
{
|
||||
if (ReferenceEquals(tab.Target as Type, type))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var inspector = new StaticInspector(type);
|
||||
|
||||
m_currentInspectors.Add(inspector);
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void SetInspectorTab(InspectorBase inspector)
|
||||
{
|
||||
MainMenu.Instance.SetPage(HomePage.Instance);
|
||||
|
||||
if (m_activeInspector == inspector)
|
||||
return;
|
||||
|
||||
UnsetInspectorTab();
|
||||
|
||||
m_activeInspector = inspector;
|
||||
inspector.SetActive();
|
||||
|
||||
UI.OnSetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void UnsetInspectorTab()
|
||||
{
|
||||
if (m_activeInspector == null)
|
||||
return;
|
||||
|
||||
m_activeInspector.SetInactive();
|
||||
|
||||
UI.OnUnsetInspectorTab();
|
||||
|
||||
m_activeInspector = null;
|
||||
}
|
||||
}
|
||||
}
|
101
src/Core/Inspectors/GameObjects/GameObjectInspector.cs
Normal file
101
src/Core/Inspectors/GameObjects/GameObjectInspector.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class GameObjectInspector : InspectorBase
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[G]</color> {TargetGO?.name}";
|
||||
|
||||
public static GameObjectInspector ActiveInstance { get; private set; }
|
||||
|
||||
public GameObject TargetGO;
|
||||
|
||||
public GameObjectInspectorUI UIModule;
|
||||
|
||||
// sub modules
|
||||
internal static ChildList s_childList;
|
||||
internal static ComponentList s_compList;
|
||||
internal static GameObjectControls s_controls;
|
||||
|
||||
internal static bool m_UIConstructed;
|
||||
|
||||
public GameObjectInspector(GameObject target) : base(target)
|
||||
{
|
||||
ActiveInstance = this;
|
||||
|
||||
TargetGO = target;
|
||||
|
||||
if (!TargetGO)
|
||||
{
|
||||
ExplorerCore.LogWarning("Target GameObject is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
// one UI is used for all gameobject inspectors. no point recreating it.
|
||||
if (!m_UIConstructed)
|
||||
{
|
||||
m_UIConstructed = true;
|
||||
|
||||
s_childList = new ChildList();
|
||||
s_compList = new ComponentList();
|
||||
s_controls = new GameObjectControls();
|
||||
|
||||
UIModule.ConstructUI();
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetActive()
|
||||
{
|
||||
base.SetActive();
|
||||
ActiveInstance = this;
|
||||
}
|
||||
|
||||
public override void SetInactive()
|
||||
{
|
||||
base.SetInactive();
|
||||
ActiveInstance = null;
|
||||
}
|
||||
|
||||
internal void ChangeInspectorTarget(GameObject newTarget)
|
||||
{
|
||||
if (!newTarget)
|
||||
return;
|
||||
|
||||
this.Target = this.TargetGO = newTarget;
|
||||
}
|
||||
|
||||
// Update
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (m_pendingDestroy || !this.IsActive)
|
||||
return;
|
||||
|
||||
UIModule.RefreshTopInfo();
|
||||
|
||||
s_childList.RefreshChildObjectList();
|
||||
|
||||
s_compList.RefreshComponentList();
|
||||
|
||||
s_controls.RefreshControls();
|
||||
|
||||
if (GameObjectControls.s_sliderChangedWanted)
|
||||
GameObjectControls.UpdateSliderControl();
|
||||
}
|
||||
|
||||
public override void CreateUIModule()
|
||||
{
|
||||
base.BaseUI = UIModule = new GameObjectInspectorUI();
|
||||
}
|
||||
}
|
||||
}
|
294
src/Core/Inspectors/InspectUnderMouse.cs
Normal file
294
src/Core/Inspectors/InspectUnderMouse.cs
Normal file
@ -0,0 +1,294 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class InspectUnderMouse
|
||||
{
|
||||
public enum MouseInspectMode
|
||||
{
|
||||
World,
|
||||
UI
|
||||
}
|
||||
|
||||
public static bool Enabled { get; set; }
|
||||
|
||||
public static MouseInspectMode Mode { get; set; }
|
||||
|
||||
private static GameObject s_lastHit;
|
||||
private static Vector3 s_lastMousePos;
|
||||
|
||||
internal static MouseInspectorUI UI;
|
||||
|
||||
static InspectUnderMouse()
|
||||
{
|
||||
UI = new MouseInspectorUI();
|
||||
}
|
||||
|
||||
private static readonly List<Graphic> _wasDisabledGraphics = new List<Graphic>();
|
||||
private static readonly List<CanvasGroup> _wasDisabledCanvasGroups = new List<CanvasGroup>();
|
||||
private static readonly List<GameObject> _objectsAddedCastersTo = new List<GameObject>();
|
||||
|
||||
public static void StartInspect(MouseInspectMode mode)
|
||||
{
|
||||
Mode = mode;
|
||||
Enabled = true;
|
||||
MainMenu.Instance.MainPanel.SetActive(false);
|
||||
|
||||
UI.s_UIContent.SetActive(true);
|
||||
|
||||
if (mode == MouseInspectMode.UI)
|
||||
{
|
||||
SetupUIRaycast();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ClearHitData()
|
||||
{
|
||||
s_lastHit = null;
|
||||
UI.s_objNameLabel.text = "No hits...";
|
||||
UI.s_objPathLabel.text = "";
|
||||
}
|
||||
|
||||
public static void StopInspect()
|
||||
{
|
||||
Enabled = false;
|
||||
MainMenu.Instance.MainPanel.SetActive(true);
|
||||
UI.s_UIContent.SetActive(false);
|
||||
|
||||
if (Mode == MouseInspectMode.UI)
|
||||
StopUIInspect();
|
||||
|
||||
ClearHitData();
|
||||
}
|
||||
|
||||
internal static GraphicRaycaster[] m_gCasters;
|
||||
|
||||
public static void UpdateInspect()
|
||||
{
|
||||
if (InputManager.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
StopInspect();
|
||||
return;
|
||||
}
|
||||
|
||||
var mousePos = InputManager.MousePosition;
|
||||
|
||||
if (mousePos != s_lastMousePos)
|
||||
UpdatePosition(mousePos);
|
||||
|
||||
if (!UnityHelper.MainCamera)
|
||||
return;
|
||||
|
||||
// actual inspect raycast
|
||||
|
||||
switch (Mode)
|
||||
{
|
||||
case MouseInspectMode.UI:
|
||||
RaycastUI(mousePos); break;
|
||||
case MouseInspectMode.World:
|
||||
RaycastWorld(mousePos); break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdatePosition(Vector2 mousePos)
|
||||
{
|
||||
s_lastMousePos = mousePos;
|
||||
|
||||
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
|
||||
|
||||
UI.s_mousePosLabel.text = $"<color=grey>Mouse Position:</color> {mousePos.ToString()}";
|
||||
|
||||
float yFix = mousePos.y < 120 ? 80 : -80;
|
||||
UI.s_UIContent.transform.localPosition = new Vector3(inversePos.x, inversePos.y + yFix, 0);
|
||||
}
|
||||
|
||||
internal static void OnHitGameObject(GameObject obj)
|
||||
{
|
||||
if (obj != s_lastHit)
|
||||
{
|
||||
s_lastHit = obj;
|
||||
UI.s_objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
||||
UI.s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
||||
}
|
||||
|
||||
if (InputManager.GetMouseButtonDown(0))
|
||||
{
|
||||
StopInspect();
|
||||
InspectorManager.Instance.Inspect(obj);
|
||||
}
|
||||
}
|
||||
|
||||
// Collider raycasting
|
||||
|
||||
internal static void RaycastWorld(Vector2 mousePos)
|
||||
{
|
||||
var ray = UnityHelper.MainCamera.ScreenPointToRay(mousePos);
|
||||
Physics.Raycast(ray, out RaycastHit hit, 1000f);
|
||||
|
||||
if (hit.transform)
|
||||
{
|
||||
var obj = hit.transform.gameObject;
|
||||
OnHitGameObject(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_lastHit)
|
||||
ClearHitData();
|
||||
}
|
||||
}
|
||||
|
||||
// UI Graphic raycasting
|
||||
|
||||
private static void SetupUIRaycast()
|
||||
{
|
||||
foreach (var obj in RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(Canvas)))
|
||||
{
|
||||
var canvas = obj.Cast(typeof(Canvas)) as Canvas;
|
||||
if (!canvas || !canvas.enabled || !canvas.gameObject.activeInHierarchy)
|
||||
continue;
|
||||
if (!canvas.GetComponent<GraphicRaycaster>())
|
||||
{
|
||||
canvas.gameObject.AddComponent<GraphicRaycaster>();
|
||||
//ExplorerCore.Log("Added raycaster to " + canvas.name);
|
||||
_objectsAddedCastersTo.Add(canvas.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// recache Graphic Raycasters each time we start
|
||||
var casters = RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(GraphicRaycaster));
|
||||
m_gCasters = new GraphicRaycaster[casters.Length];
|
||||
for (int i = 0; i < casters.Length; i++)
|
||||
{
|
||||
m_gCasters[i] = casters[i].Cast(typeof(GraphicRaycaster)) as GraphicRaycaster;
|
||||
}
|
||||
|
||||
// enable raycastTarget on Graphics
|
||||
foreach (var obj in RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(Graphic)))
|
||||
{
|
||||
var graphic = obj.Cast(typeof(Graphic)) as Graphic;
|
||||
if (!graphic || !graphic.enabled || graphic.raycastTarget || !graphic.gameObject.activeInHierarchy)
|
||||
continue;
|
||||
graphic.raycastTarget = true;
|
||||
//ExplorerCore.Log("Enabled raycastTarget on " + graphic.name);
|
||||
_wasDisabledGraphics.Add(graphic);
|
||||
}
|
||||
|
||||
// enable blocksRaycasts on CanvasGroups
|
||||
foreach (var obj in RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(CanvasGroup)))
|
||||
{
|
||||
var canvas = obj.Cast(typeof(CanvasGroup)) as CanvasGroup;
|
||||
if (!canvas || !canvas.gameObject.activeInHierarchy || canvas.blocksRaycasts)
|
||||
continue;
|
||||
canvas.blocksRaycasts = true;
|
||||
//ExplorerCore.Log("Enabled raycasts on " + canvas.name);
|
||||
_wasDisabledCanvasGroups.Add(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RaycastUI(Vector2 mousePos)
|
||||
{
|
||||
var ped = new PointerEventData(null)
|
||||
{
|
||||
position = mousePos
|
||||
};
|
||||
|
||||
#if MONO
|
||||
var list = new List<RaycastResult>();
|
||||
#else
|
||||
var list = new Il2CppSystem.Collections.Generic.List<RaycastResult>();
|
||||
#endif
|
||||
//ExplorerCore.Log("~~~~~~~~~ begin raycast ~~~~~~~~");
|
||||
GameObject hitObject = null;
|
||||
int highestLayer = int.MinValue;
|
||||
int highestOrder = int.MinValue;
|
||||
int highestDepth = int.MinValue;
|
||||
foreach (var gr in m_gCasters)
|
||||
{
|
||||
gr.Raycast(ped, list);
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
foreach (var hit in list)
|
||||
{
|
||||
if (!hit.gameObject)
|
||||
continue;
|
||||
|
||||
if (hit.gameObject.GetComponent<CanvasGroup>() is CanvasGroup group && group.alpha == 0)
|
||||
continue;
|
||||
|
||||
if (hit.gameObject.GetComponent<Graphic>() is Graphic graphic && graphic.color.a == 0f)
|
||||
continue;
|
||||
|
||||
//ExplorerCore.Log("Hit: " + hit.gameObject.name + ", depth: " + hit.depth + ", layer: " + hit.sortingLayer + ", order: " + hit.sortingOrder);
|
||||
|
||||
if (hit.sortingLayer < highestLayer)
|
||||
continue;
|
||||
|
||||
if (hit.sortingLayer > highestLayer)
|
||||
{
|
||||
highestLayer = hit.sortingLayer;
|
||||
highestOrder = int.MinValue;
|
||||
}
|
||||
|
||||
if (hit.depth < highestDepth)
|
||||
continue;
|
||||
|
||||
if (hit.depth > highestDepth)
|
||||
{
|
||||
highestDepth = hit.depth;
|
||||
highestOrder = int.MinValue;
|
||||
}
|
||||
|
||||
if (hit.sortingOrder <= highestOrder)
|
||||
continue;
|
||||
|
||||
highestOrder = hit.sortingOrder;
|
||||
hitObject = hit.gameObject;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_lastHit)
|
||||
ClearHitData();
|
||||
}
|
||||
}
|
||||
|
||||
if (hitObject)
|
||||
OnHitGameObject(hitObject);
|
||||
|
||||
//ExplorerCore.Log("~~~~~~~~~ end raycast ~~~~~~~~");
|
||||
}
|
||||
|
||||
private static void StopUIInspect()
|
||||
{
|
||||
foreach (var obj in _objectsAddedCastersTo)
|
||||
{
|
||||
if (obj.GetComponent<GraphicRaycaster>() is GraphicRaycaster raycaster)
|
||||
GameObject.Destroy(raycaster);
|
||||
}
|
||||
|
||||
foreach (var graphic in _wasDisabledGraphics)
|
||||
graphic.raycastTarget = false;
|
||||
|
||||
foreach (var canvas in _wasDisabledCanvasGroups)
|
||||
canvas.blocksRaycasts = false;
|
||||
|
||||
_objectsAddedCastersTo.Clear();
|
||||
_wasDisabledCanvasGroups.Clear();
|
||||
_wasDisabledGraphics.Clear();
|
||||
}
|
||||
}
|
||||
}
|
92
src/Core/Inspectors/InspectorBase.cs
Normal file
92
src/Core/Inspectors/InspectorBase.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public abstract class InspectorBase
|
||||
{
|
||||
public object Target;
|
||||
|
||||
public InspectorBaseUI BaseUI;
|
||||
|
||||
public abstract string TabLabel { get; }
|
||||
|
||||
public bool IsActive { get; private set; }
|
||||
|
||||
internal bool m_pendingDestroy;
|
||||
|
||||
public InspectorBase(object target)
|
||||
{
|
||||
Target = target;
|
||||
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
CreateUIModule();
|
||||
|
||||
BaseUI.AddInspectorTab(this);
|
||||
}
|
||||
|
||||
public abstract void CreateUIModule();
|
||||
|
||||
public virtual void SetActive()
|
||||
{
|
||||
this.IsActive = true;
|
||||
BaseUI.Content?.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void SetInactive()
|
||||
{
|
||||
this.IsActive = false;
|
||||
BaseUI.Content?.SetActive(false);
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
BaseUI.tabText.text = TabLabel;
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
m_pendingDestroy = true;
|
||||
|
||||
GameObject tabGroup = BaseUI.tabButton?.transform.parent.gameObject;
|
||||
|
||||
if (tabGroup)
|
||||
{
|
||||
GameObject.Destroy(tabGroup);
|
||||
}
|
||||
|
||||
int thisIndex = -1;
|
||||
if (InspectorManager.Instance.m_currentInspectors.Contains(this))
|
||||
{
|
||||
thisIndex = InspectorManager.Instance.m_currentInspectors.IndexOf(this);
|
||||
InspectorManager.Instance.m_currentInspectors.Remove(this);
|
||||
}
|
||||
|
||||
if (ReferenceEquals(InspectorManager.Instance.m_activeInspector, this))
|
||||
{
|
||||
InspectorManager.Instance.UnsetInspectorTab();
|
||||
|
||||
if (InspectorManager.Instance.m_currentInspectors.Count > 0)
|
||||
{
|
||||
var prevTab = InspectorManager.Instance.m_currentInspectors[thisIndex > 0 ? thisIndex - 1 : 0];
|
||||
InspectorManager.Instance.SetInspectorTab(prevTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheEnumerated : CacheObjectBase
|
||||
{
|
||||
public override Type FallbackType => ParentEnumeration.m_baseEntryType;
|
||||
public override bool CanWrite => RefIList != null && ParentEnumeration.Owner.CanWrite;
|
||||
|
||||
public int Index { get; set; }
|
||||
public IList RefIList { get; set; }
|
||||
public InteractiveEnumerable ParentEnumeration { get; set; }
|
||||
|
||||
public CacheEnumerated(int index, InteractiveEnumerable parentEnumeration, IList refIList, GameObject parentContent)
|
||||
{
|
||||
this.ParentEnumeration = parentEnumeration;
|
||||
this.Index = index;
|
||||
this.RefIList = refIList;
|
||||
this.m_parentContent = parentContent;
|
||||
}
|
||||
|
||||
public override void CreateIValue(object value, Type fallbackType)
|
||||
{
|
||||
IValue = InteractiveValue.Create(value, fallbackType);
|
||||
IValue.Owner = this;
|
||||
}
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
RefIList[Index] = IValue.Value;
|
||||
ParentEnumeration.Value = RefIList;
|
||||
|
||||
ParentEnumeration.Owner.SetValue();
|
||||
}
|
||||
|
||||
internal override void ConstructUI()
|
||||
{
|
||||
base.ConstructUI();
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(m_mainContent, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.padding.left = 5;
|
||||
rowGroup.padding.right = 2;
|
||||
|
||||
var indexLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
var indexLayout = indexLabelObj.AddComponent<LayoutElement>();
|
||||
indexLayout.minWidth = 20;
|
||||
indexLayout.flexibleWidth = 30;
|
||||
indexLayout.minHeight = 25;
|
||||
var indexText = indexLabelObj.GetComponent<Text>();
|
||||
indexText.text = this.Index + ":";
|
||||
|
||||
IValue.m_mainContentParent = rowObj;
|
||||
}
|
||||
}
|
||||
}
|
40
src/Core/Inspectors/Reflection/CacheObject/CacheField.cs
Normal file
40
src/Core/Inspectors/Reflection/CacheObject/CacheField.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheField : CacheMember
|
||||
{
|
||||
public override bool IsStatic => (MemInfo as FieldInfo).IsStatic;
|
||||
|
||||
public override Type FallbackType => (MemInfo as FieldInfo).FieldType;
|
||||
|
||||
public CacheField(FieldInfo fieldInfo, object declaringInstance, GameObject parent) : base(fieldInfo, declaringInstance, parent)
|
||||
{
|
||||
CreateIValue(null, fieldInfo.FieldType);
|
||||
}
|
||||
|
||||
public override void UpdateReflection()
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
IValue.Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance);
|
||||
|
||||
m_evaluated = true;
|
||||
ReflectionException = null;
|
||||
}
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
fi.SetValue(fi.IsStatic ? null : DeclaringInstance, IValue.Value);
|
||||
|
||||
if (this.ParentInspector?.ParentMember != null)
|
||||
this.ParentInspector.ParentMember.SetValue();
|
||||
}
|
||||
}
|
||||
}
|
465
src/Core/Inspectors/Reflection/CacheObject/CacheMember.cs
Normal file
465
src/Core/Inspectors/Reflection/CacheObject/CacheMember.cs
Normal file
@ -0,0 +1,465 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public abstract class CacheMember : CacheObjectBase
|
||||
{
|
||||
public override bool IsMember => true;
|
||||
|
||||
public override Type FallbackType { get; }
|
||||
|
||||
public ReflectionInspector ParentInspector { get; set; }
|
||||
public MemberInfo MemInfo { get; set; }
|
||||
public Type DeclaringType { get; set; }
|
||||
public object DeclaringInstance { get; set; }
|
||||
public virtual bool IsStatic { get; private set; }
|
||||
|
||||
public string ReflectionException { get; set; }
|
||||
|
||||
public override bool CanWrite => m_canWrite ?? GetCanWrite();
|
||||
private bool? m_canWrite;
|
||||
|
||||
public override bool HasParameters => ParamCount > 0;
|
||||
public virtual int ParamCount => m_arguments.Length;
|
||||
public override bool HasEvaluated => m_evaluated;
|
||||
public bool m_evaluated = false;
|
||||
public bool m_isEvaluating;
|
||||
public ParameterInfo[] m_arguments = new ParameterInfo[0];
|
||||
public string[] m_argumentInput = new string[0];
|
||||
|
||||
public string NameForFiltering => m_nameForFilter ?? (m_nameForFilter = $"{MemInfo.DeclaringType.Name}.{MemInfo.Name}".ToLower());
|
||||
private string m_nameForFilter;
|
||||
|
||||
public string RichTextName => m_richTextName ?? GetRichTextName();
|
||||
private string m_richTextName;
|
||||
|
||||
public CacheMember(MemberInfo memberInfo, object declaringInstance, GameObject parentContent)
|
||||
{
|
||||
MemInfo = memberInfo;
|
||||
DeclaringType = memberInfo.DeclaringType;
|
||||
DeclaringInstance = declaringInstance;
|
||||
this.m_parentContent = parentContent;
|
||||
|
||||
DeclaringInstance = ReflectionProvider.Instance.Cast(declaringInstance, DeclaringType);
|
||||
}
|
||||
|
||||
public static bool CanProcessArgs(ParameterInfo[] parameters)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
var pType = param.ParameterType;
|
||||
|
||||
if (pType.IsByRef && pType.HasElementType)
|
||||
pType = pType.GetElementType();
|
||||
|
||||
if (pType != null && (pType.IsPrimitive || pType == typeof(string)))
|
||||
continue;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void CreateIValue(object value, Type fallbackType)
|
||||
{
|
||||
IValue = InteractiveValue.Create(value, fallbackType);
|
||||
IValue.Owner = this;
|
||||
IValue.m_mainContentParent = this.m_rightGroup;
|
||||
IValue.m_subContentParent = this.m_subContent;
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
if (!HasParameters || m_isEvaluating)
|
||||
{
|
||||
try
|
||||
{
|
||||
Type baseType = ReflectionUtility.GetType(IValue.Value) ?? FallbackType;
|
||||
|
||||
if (!ReflectionProvider.Instance.IsReflectionSupported(baseType))
|
||||
throw new Exception("Type not supported with reflection");
|
||||
|
||||
UpdateReflection();
|
||||
|
||||
if (IValue.Value != null)
|
||||
IValue.Value = IValue.Value.Cast(ReflectionUtility.GetType(IValue.Value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ReflectionException = e.ReflectionExToString(true);
|
||||
}
|
||||
}
|
||||
|
||||
base.UpdateValue();
|
||||
}
|
||||
|
||||
public abstract void UpdateReflection();
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
// no implementation for base class
|
||||
}
|
||||
|
||||
public object[] ParseArguments()
|
||||
{
|
||||
if (m_arguments.Length < 1)
|
||||
return new object[0];
|
||||
|
||||
var parsedArgs = new List<object>();
|
||||
for (int i = 0; i < m_arguments.Length; i++)
|
||||
{
|
||||
var input = m_argumentInput[i];
|
||||
var type = m_arguments[i].ParameterType;
|
||||
|
||||
if (type.IsByRef)
|
||||
type = type.GetElementType();
|
||||
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
if (type == typeof(string))
|
||||
{
|
||||
parsedArgs.Add(input);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var arg = type.GetMethod("Parse", new Type[] { typeof(string) })
|
||||
.Invoke(null, new object[] { input });
|
||||
|
||||
parsedArgs.Add(arg);
|
||||
continue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
ExplorerCore.Log($"Could not parse input '{input}' for argument #{i} '{m_arguments[i].Name}' ({type.FullName})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No input, see if there is a default value.
|
||||
if (m_arguments[i].IsOptional)
|
||||
{
|
||||
parsedArgs.Add(m_arguments[i].DefaultValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try add a null arg I guess
|
||||
parsedArgs.Add(null);
|
||||
}
|
||||
|
||||
return parsedArgs.ToArray();
|
||||
}
|
||||
|
||||
private bool GetCanWrite()
|
||||
{
|
||||
if (MemInfo is FieldInfo fi)
|
||||
m_canWrite = !(fi.IsLiteral && !fi.IsInitOnly);
|
||||
else if (MemInfo is PropertyInfo pi)
|
||||
m_canWrite = pi.CanWrite;
|
||||
else
|
||||
m_canWrite = false;
|
||||
|
||||
return (bool)m_canWrite;
|
||||
}
|
||||
|
||||
private string GetRichTextName()
|
||||
{
|
||||
return m_richTextName = SignatureHighlighter.ParseFullSyntax(MemInfo.DeclaringType, false, MemInfo);
|
||||
}
|
||||
|
||||
#region UI
|
||||
|
||||
internal float GetMemberLabelWidth(RectTransform scrollRect)
|
||||
{
|
||||
var textGenSettings = m_memLabelText.GetGenerationSettings(m_topRowRect.rect.size);
|
||||
textGenSettings.scaleFactor = InputFieldScroller.canvasScaler.scaleFactor;
|
||||
|
||||
var textGen = m_memLabelText.cachedTextGeneratorForLayout;
|
||||
float preferredWidth = textGen.GetPreferredWidth(RichTextName, textGenSettings);
|
||||
|
||||
float max = scrollRect.rect.width * 0.4f;
|
||||
|
||||
if (preferredWidth > max) preferredWidth = max;
|
||||
|
||||
return preferredWidth < 125f ? 125f : preferredWidth;
|
||||
}
|
||||
|
||||
internal void SetWidths(float labelWidth, float valueWidth)
|
||||
{
|
||||
m_leftLayout.preferredWidth = labelWidth;
|
||||
m_rightLayout.preferredWidth = valueWidth;
|
||||
}
|
||||
|
||||
internal RectTransform m_topRowRect;
|
||||
internal Text m_memLabelText;
|
||||
internal GameObject m_leftGroup;
|
||||
internal LayoutElement m_leftLayout;
|
||||
internal GameObject m_rightGroup;
|
||||
internal LayoutElement m_rightLayout;
|
||||
|
||||
internal override void ConstructUI()
|
||||
{
|
||||
base.ConstructUI();
|
||||
|
||||
var topGroupObj = UIFactory.CreateHorizontalGroup(m_mainContent, new Color(1, 1, 1, 0));
|
||||
m_topRowRect = topGroupObj.GetComponent<RectTransform>();
|
||||
var topLayout = topGroupObj.AddComponent<LayoutElement>();
|
||||
topLayout.minHeight = 25;
|
||||
topLayout.flexibleHeight = 0;
|
||||
topLayout.minWidth = 300;
|
||||
topLayout.flexibleWidth = 5000;
|
||||
var topGroup = topGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
topGroup.childForceExpandHeight = false;
|
||||
topGroup.childForceExpandWidth = false;
|
||||
topGroup.SetChildControlHeight(true);
|
||||
topGroup.SetChildControlWidth(true);
|
||||
topGroup.spacing = 10;
|
||||
topGroup.padding.left = 3;
|
||||
topGroup.padding.right = 3;
|
||||
topGroup.padding.top = 0;
|
||||
topGroup.padding.bottom = 0;
|
||||
|
||||
// left group
|
||||
|
||||
m_leftGroup = UIFactory.CreateHorizontalGroup(topGroupObj, new Color(1, 1, 1, 0));
|
||||
var leftLayout = m_leftGroup.AddComponent<LayoutElement>();
|
||||
leftLayout.minHeight = 25;
|
||||
leftLayout.flexibleHeight = 0;
|
||||
leftLayout.minWidth = 125;
|
||||
leftLayout.flexibleWidth = 200;
|
||||
var leftGroup = m_leftGroup.GetComponent<HorizontalLayoutGroup>();
|
||||
leftGroup.childForceExpandHeight = true;
|
||||
leftGroup.childForceExpandWidth = false;
|
||||
leftGroup.SetChildControlHeight(true);
|
||||
leftGroup.SetChildControlWidth(true);
|
||||
leftGroup.spacing = 4;
|
||||
|
||||
// member label
|
||||
|
||||
var labelObj = UIFactory.CreateLabel(m_leftGroup, TextAnchor.MiddleLeft);
|
||||
var leftRect = labelObj.GetComponent<RectTransform>();
|
||||
leftRect.anchorMin = Vector2.zero;
|
||||
leftRect.anchorMax = Vector2.one;
|
||||
leftRect.offsetMin = Vector2.zero;
|
||||
leftRect.offsetMax = Vector2.zero;
|
||||
leftRect.sizeDelta = Vector2.zero;
|
||||
m_leftLayout = labelObj.AddComponent<LayoutElement>();
|
||||
m_leftLayout.preferredWidth = 125;
|
||||
m_leftLayout.minHeight = 25;
|
||||
m_leftLayout.flexibleHeight = 100;
|
||||
var labelFitter = labelObj.AddComponent<ContentSizeFitter>();
|
||||
labelFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
labelFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
m_memLabelText = labelObj.GetComponent<Text>();
|
||||
m_memLabelText.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
m_memLabelText.text = this.RichTextName;
|
||||
|
||||
// right group
|
||||
|
||||
m_rightGroup = UIFactory.CreateVerticalGroup(topGroupObj, new Color(1, 1, 1, 0));
|
||||
m_rightLayout = m_rightGroup.AddComponent<LayoutElement>();
|
||||
m_rightLayout.minHeight = 25;
|
||||
m_rightLayout.flexibleHeight = 480;
|
||||
m_rightLayout.minWidth = 125;
|
||||
m_rightLayout.flexibleWidth = 5000;
|
||||
var rightGroup = m_rightGroup.GetComponent<VerticalLayoutGroup>();
|
||||
rightGroup.childForceExpandHeight = true;
|
||||
rightGroup.childForceExpandWidth = false;
|
||||
rightGroup.SetChildControlHeight(true);
|
||||
rightGroup.SetChildControlWidth(true);
|
||||
rightGroup.spacing = 2;
|
||||
rightGroup.padding.top = 4;
|
||||
rightGroup.padding.bottom = 2;
|
||||
|
||||
ConstructArgInput(out GameObject argsHolder);
|
||||
|
||||
ConstructEvaluateButtons(argsHolder);
|
||||
|
||||
IValue.m_mainContentParent = m_rightGroup;
|
||||
}
|
||||
|
||||
internal void ConstructArgInput(out GameObject argsHolder)
|
||||
{
|
||||
argsHolder = null;
|
||||
|
||||
if (HasParameters)
|
||||
{
|
||||
argsHolder = UIFactory.CreateVerticalGroup(m_rightGroup, new Color(1, 1, 1, 0));
|
||||
var argsGroup = argsHolder.GetComponent<VerticalLayoutGroup>();
|
||||
argsGroup.spacing = 4;
|
||||
|
||||
if (this is CacheMethod cm && cm.GenericArgs.Length > 0)
|
||||
{
|
||||
cm.ConstructGenericArgInput(argsHolder);
|
||||
}
|
||||
|
||||
// todo normal args
|
||||
|
||||
if (m_arguments.Length > 0)
|
||||
{
|
||||
var titleObj = UIFactory.CreateLabel(argsHolder, TextAnchor.MiddleLeft);
|
||||
var titleText = titleObj.GetComponent<Text>();
|
||||
titleText.text = "<b>Arguments:</b>";
|
||||
|
||||
for (int i = 0; i < m_arguments.Length; i++)
|
||||
{
|
||||
AddArgRow(i, argsHolder);
|
||||
}
|
||||
}
|
||||
|
||||
argsHolder.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddArgRow(int i, GameObject parent)
|
||||
{
|
||||
var arg = m_arguments[i];
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||
var rowLayout = rowObj.AddComponent<LayoutElement>();
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleWidth = 5000;
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childForceExpandHeight = false;
|
||||
rowGroup.childForceExpandWidth = true;
|
||||
rowGroup.spacing = 4;
|
||||
|
||||
var argLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
var argLabelLayout = argLabelObj.AddComponent<LayoutElement>();
|
||||
argLabelLayout.minHeight = 25;
|
||||
var argText = argLabelObj.GetComponent<Text>();
|
||||
var argTypeTxt = SignatureHighlighter.ParseFullSyntax(arg.ParameterType, false);
|
||||
argText.text = $"{argTypeTxt} <color={SignatureHighlighter.LOCAL_ARG}>{arg.Name}</color>";
|
||||
|
||||
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
|
||||
var argInputLayout = argInputObj.AddComponent<LayoutElement>();
|
||||
argInputLayout.flexibleWidth = 1200;
|
||||
argInputLayout.preferredWidth = 150;
|
||||
argInputLayout.minWidth = 20;
|
||||
argInputLayout.minHeight = 25;
|
||||
argInputLayout.flexibleHeight = 0;
|
||||
//argInputLayout.layoutPriority = 2;
|
||||
|
||||
var argInput = argInputObj.GetComponent<InputField>();
|
||||
argInput.onValueChanged.AddListener((string val) => { m_argumentInput[i] = val; });
|
||||
|
||||
if (arg.IsOptional)
|
||||
{
|
||||
var phInput = argInput.placeholder.GetComponent<Text>();
|
||||
phInput.text = " = " + arg.DefaultValue?.ToString() ?? "null";
|
||||
}
|
||||
}
|
||||
|
||||
internal void ConstructEvaluateButtons(GameObject argsHolder)
|
||||
{
|
||||
if (HasParameters)
|
||||
{
|
||||
var evalGroupObj = UIFactory.CreateHorizontalGroup(m_rightGroup, new Color(1, 1, 1, 0));
|
||||
var evalGroup = evalGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
evalGroup.childForceExpandWidth = false;
|
||||
evalGroup.childForceExpandHeight = false;
|
||||
evalGroup.spacing = 5;
|
||||
var evalGroupLayout = evalGroupObj.AddComponent<LayoutElement>();
|
||||
evalGroupLayout.minHeight = 25;
|
||||
evalGroupLayout.flexibleHeight = 0;
|
||||
evalGroupLayout.flexibleWidth = 5000;
|
||||
|
||||
var evalButtonObj = UIFactory.CreateButton(evalGroupObj, new Color(0.4f, 0.4f, 0.4f));
|
||||
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
|
||||
evalLayout.minWidth = 100;
|
||||
evalLayout.minHeight = 22;
|
||||
evalLayout.flexibleWidth = 0;
|
||||
var evalText = evalButtonObj.GetComponentInChildren<Text>();
|
||||
evalText.text = $"Evaluate ({ParamCount})";
|
||||
|
||||
var evalButton = evalButtonObj.GetComponent<Button>();
|
||||
var colors = evalButton.colors;
|
||||
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
|
||||
evalButton.colors = colors;
|
||||
|
||||
var cancelButtonObj = UIFactory.CreateButton(evalGroupObj, new Color(0.3f, 0.3f, 0.3f));
|
||||
var cancelLayout = cancelButtonObj.AddComponent<LayoutElement>();
|
||||
cancelLayout.minWidth = 100;
|
||||
cancelLayout.minHeight = 22;
|
||||
cancelLayout.flexibleWidth = 0;
|
||||
var cancelText = cancelButtonObj.GetComponentInChildren<Text>();
|
||||
cancelText.text = "Close";
|
||||
|
||||
cancelButtonObj.SetActive(false);
|
||||
|
||||
evalButton.onClick.AddListener(() =>
|
||||
{
|
||||
if (!m_isEvaluating)
|
||||
{
|
||||
argsHolder.SetActive(true);
|
||||
m_isEvaluating = true;
|
||||
evalText.text = "Evaluate";
|
||||
colors = evalButton.colors;
|
||||
colors.normalColor = new Color(0.3f, 0.6f, 0.3f);
|
||||
evalButton.colors = colors;
|
||||
|
||||
cancelButtonObj.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this is CacheMethod cm)
|
||||
cm.Evaluate();
|
||||
else
|
||||
UpdateValue();
|
||||
}
|
||||
});
|
||||
|
||||
var cancelButton = cancelButtonObj.GetComponent<Button>();
|
||||
cancelButton.onClick.AddListener(() =>
|
||||
{
|
||||
cancelButtonObj.SetActive(false);
|
||||
argsHolder.SetActive(false);
|
||||
m_isEvaluating = false;
|
||||
|
||||
evalText.text = $"Evaluate ({ParamCount})";
|
||||
colors = evalButton.colors;
|
||||
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
|
||||
evalButton.colors = colors;
|
||||
});
|
||||
}
|
||||
else if (this is CacheMethod)
|
||||
{
|
||||
// simple method evaluate button
|
||||
|
||||
var evalButtonObj = UIFactory.CreateButton(m_rightGroup, new Color(0.3f, 0.6f, 0.3f));
|
||||
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
|
||||
evalLayout.minWidth = 100;
|
||||
evalLayout.minHeight = 22;
|
||||
evalLayout.flexibleWidth = 0;
|
||||
var evalText = evalButtonObj.GetComponentInChildren<Text>();
|
||||
evalText.text = "Evaluate";
|
||||
|
||||
var evalButton = evalButtonObj.GetComponent<Button>();
|
||||
var colors = evalButton.colors;
|
||||
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
|
||||
evalButton.colors = colors;
|
||||
|
||||
evalButton.onClick.AddListener(OnMainEvaluateButton);
|
||||
void OnMainEvaluateButton()
|
||||
{
|
||||
(this as CacheMethod).Evaluate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
192
src/Core/Inspectors/Reflection/CacheObject/CacheMethod.cs
Normal file
192
src/Core/Inspectors/Reflection/CacheObject/CacheMethod.cs
Normal file
@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheMethod : CacheMember
|
||||
{
|
||||
//private CacheObjectBase m_cachedReturnValue;
|
||||
|
||||
public override Type FallbackType => (MemInfo as MethodInfo).ReturnType;
|
||||
|
||||
public override bool HasParameters => base.HasParameters || GenericArgs.Length > 0;
|
||||
|
||||
public override bool IsStatic => (MemInfo as MethodInfo).IsStatic;
|
||||
|
||||
public override int ParamCount => base.ParamCount + m_genericArgInput.Length;
|
||||
|
||||
public Type[] GenericArgs { get; private set; }
|
||||
public Type[][] GenericConstraints { get; private set; }
|
||||
|
||||
public string[] m_genericArgInput = new string[0];
|
||||
|
||||
public CacheMethod(MethodInfo methodInfo, object declaringInstance, GameObject parent) : base(methodInfo, declaringInstance, parent)
|
||||
{
|
||||
GenericArgs = methodInfo.GetGenericArguments();
|
||||
|
||||
GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints())
|
||||
.Where(x => x != null)
|
||||
.ToArray();
|
||||
|
||||
m_genericArgInput = new string[GenericArgs.Length];
|
||||
|
||||
m_arguments = methodInfo.GetParameters();
|
||||
m_argumentInput = new string[m_arguments.Length];
|
||||
|
||||
CreateIValue(null, methodInfo.ReturnType);
|
||||
}
|
||||
|
||||
public override void UpdateReflection()
|
||||
{
|
||||
// CacheMethod cannot UpdateValue directly. Need to Evaluate.
|
||||
}
|
||||
|
||||
public void Evaluate()
|
||||
{
|
||||
MethodInfo mi;
|
||||
if (GenericArgs.Length > 0)
|
||||
{
|
||||
mi = MakeGenericMethodFromInput();
|
||||
if (mi == null) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
mi = MemInfo as MethodInfo;
|
||||
}
|
||||
|
||||
object ret = null;
|
||||
|
||||
try
|
||||
{
|
||||
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
||||
m_evaluated = true;
|
||||
m_isEvaluating = false;
|
||||
ReflectionException = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
while (e.InnerException != null)
|
||||
e = e.InnerException;
|
||||
|
||||
ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||
ReflectionException = ReflectionUtility.ReflectionExToString(e);
|
||||
}
|
||||
|
||||
IValue.Value = ret;
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
private MethodInfo MakeGenericMethodFromInput()
|
||||
{
|
||||
var mi = MemInfo as MethodInfo;
|
||||
|
||||
var list = new List<Type>();
|
||||
for (int i = 0; i < GenericArgs.Length; i++)
|
||||
{
|
||||
var input = m_genericArgInput[i];
|
||||
if (ReflectionUtility.GetTypeByName(input) is Type t)
|
||||
{
|
||||
if (GenericConstraints[i].Length == 0)
|
||||
{
|
||||
list.Add(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var constraint in GenericConstraints[i].Where(x => x != null))
|
||||
{
|
||||
if (!constraint.IsAssignableFrom(t))
|
||||
{
|
||||
ExplorerCore.LogWarning($"Generic argument #{i}, '{input}' is not assignable from the constraint '{constraint}'!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
list.Add(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
|
||||
$" Make sure you use the full name including the namespace.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// make into a generic with type list
|
||||
mi = mi.MakeGenericMethod(list.ToArray());
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal void ConstructGenericArgInput(GameObject parent)
|
||||
{
|
||||
var titleObj = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
|
||||
var titleText = titleObj.GetComponent<Text>();
|
||||
titleText.text = "<b>Generic Arguments:</b>";
|
||||
|
||||
for (int i = 0; i < GenericArgs.Length; i++)
|
||||
{
|
||||
AddGenericArgRow(i, parent);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddGenericArgRow(int i, GameObject parent)
|
||||
{
|
||||
var arg = GenericArgs[i];
|
||||
|
||||
string constrainTxt = "";
|
||||
if (this.GenericConstraints[i].Length > 0)
|
||||
{
|
||||
foreach (var constraint in this.GenericConstraints[i])
|
||||
{
|
||||
if (constrainTxt != "")
|
||||
constrainTxt += ", ";
|
||||
|
||||
constrainTxt += $"{SignatureHighlighter.ParseFullSyntax(constraint, false)}";
|
||||
}
|
||||
}
|
||||
else
|
||||
constrainTxt = $"Any";
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||
var rowLayout = rowObj.AddComponent<LayoutElement>();
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleWidth = 5000;
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childForceExpandHeight = true;
|
||||
rowGroup.spacing = 4;
|
||||
|
||||
var argLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
//var argLayout = argLabelObj.AddComponent<LayoutElement>();
|
||||
//argLayout.minWidth = 20;
|
||||
var argText = argLabelObj.GetComponent<Text>();
|
||||
argText.text = $"{constrainTxt} <color={SignatureHighlighter.CONST_VAR}>{arg.Name}</color>";
|
||||
|
||||
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
|
||||
var argInputLayout = argInputObj.AddComponent<LayoutElement>();
|
||||
argInputLayout.flexibleWidth = 1200;
|
||||
|
||||
var argInput = argInputObj.GetComponent<InputField>();
|
||||
argInput.onValueChanged.AddListener((string val) => { m_genericArgInput[i] = val; });
|
||||
|
||||
//var constraintLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
//var constraintLayout = constraintLabelObj.AddComponent<LayoutElement>();
|
||||
//constraintLayout.minWidth = 60;
|
||||
//constraintLayout.flexibleWidth = 100;
|
||||
//var constraintText = constraintLabelObj.GetComponent<Text>();
|
||||
//constraintText.text = ;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
125
src/Core/Inspectors/Reflection/CacheObject/CacheObjectBase.cs
Normal file
125
src/Core/Inspectors/Reflection/CacheObject/CacheObjectBase.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public abstract class CacheObjectBase
|
||||
{
|
||||
public InteractiveValue IValue;
|
||||
|
||||
public virtual bool CanWrite => false;
|
||||
public virtual bool HasParameters => false;
|
||||
public virtual bool IsMember => false;
|
||||
public virtual bool HasEvaluated => true;
|
||||
|
||||
public abstract Type FallbackType { get; }
|
||||
|
||||
public abstract void CreateIValue(object value, Type fallbackType);
|
||||
|
||||
public virtual void Enable()
|
||||
{
|
||||
if (!m_constructedUI)
|
||||
{
|
||||
ConstructUI();
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
m_mainContent.SetActive(true);
|
||||
m_mainContent.transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
public virtual void Disable()
|
||||
{
|
||||
if (m_mainContent)
|
||||
m_mainContent.SetActive(false);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
if (this.m_mainContent)
|
||||
GameObject.Destroy(this.m_mainContent);
|
||||
}
|
||||
|
||||
public virtual void UpdateValue()
|
||||
{
|
||||
var value = IValue.Value;
|
||||
|
||||
// if the type has changed fundamentally, make a new interactivevalue for it
|
||||
var type = value == null
|
||||
? FallbackType
|
||||
: ReflectionUtility.GetType(value);
|
||||
|
||||
var ivalueType = InteractiveValue.GetIValueForType(type);
|
||||
|
||||
if (ivalueType != IValue.GetType())
|
||||
{
|
||||
IValue.OnDestroy();
|
||||
CreateIValue(value, FallbackType);
|
||||
m_subContent.SetActive(false);
|
||||
}
|
||||
|
||||
IValue.OnValueUpdated();
|
||||
|
||||
IValue.RefreshElementsAfterUpdate();
|
||||
}
|
||||
|
||||
public virtual void SetValue() => throw new NotImplementedException();
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal bool m_constructedUI;
|
||||
internal GameObject m_parentContent;
|
||||
internal RectTransform m_mainRect;
|
||||
internal GameObject m_mainContent;
|
||||
internal GameObject m_subContent;
|
||||
|
||||
// Make base UI holder for CacheObject, this doesnt actually display anything.
|
||||
internal virtual void ConstructUI()
|
||||
{
|
||||
m_constructedUI = true;
|
||||
|
||||
m_mainContent = UIFactory.CreateVerticalGroup(m_parentContent, new Color(0.1f, 0.1f, 0.1f));
|
||||
m_mainContent.name = "CacheObjectBase.MainContent";
|
||||
m_mainRect = m_mainContent.GetComponent<RectTransform>();
|
||||
m_mainRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);
|
||||
var mainGroup = m_mainContent.GetComponent<VerticalLayoutGroup>();
|
||||
mainGroup.childForceExpandWidth = true;
|
||||
mainGroup.SetChildControlWidth(true);
|
||||
mainGroup.childForceExpandHeight = true;
|
||||
mainGroup.SetChildControlHeight(true);
|
||||
var mainLayout = m_mainContent.AddComponent<LayoutElement>();
|
||||
mainLayout.minHeight = 25;
|
||||
mainLayout.flexibleHeight = 9999;
|
||||
mainLayout.minWidth = 200;
|
||||
mainLayout.flexibleWidth = 5000;
|
||||
|
||||
// subcontent
|
||||
|
||||
m_subContent = UIFactory.CreateVerticalGroup(m_mainContent, new Color(0.085f, 0.085f, 0.085f));
|
||||
m_subContent.name = "CacheObjectBase.SubContent";
|
||||
var subGroup = m_subContent.GetComponent<VerticalLayoutGroup>();
|
||||
subGroup.childForceExpandWidth = true;
|
||||
subGroup.childForceExpandHeight = false;
|
||||
var subLayout = m_subContent.AddComponent<LayoutElement>();
|
||||
subLayout.minHeight = 30;
|
||||
subLayout.flexibleHeight = 9999;
|
||||
subLayout.minWidth = 125;
|
||||
subLayout.flexibleWidth = 9000;
|
||||
|
||||
m_subContent.SetActive(false);
|
||||
|
||||
IValue.m_subContentParent = m_subContent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
71
src/Core/Inspectors/Reflection/CacheObject/CachePaired.cs
Normal file
71
src/Core/Inspectors/Reflection/CacheObject/CachePaired.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public enum PairTypes
|
||||
{
|
||||
Key,
|
||||
Value
|
||||
}
|
||||
|
||||
public class CachePaired : CacheObjectBase
|
||||
{
|
||||
public override Type FallbackType => PairType == PairTypes.Key
|
||||
? ParentDictionary.m_typeOfKeys
|
||||
: ParentDictionary.m_typeofValues;
|
||||
|
||||
public override bool CanWrite => false; // todo?
|
||||
|
||||
public PairTypes PairType;
|
||||
public int Index { get; private set; }
|
||||
public InteractiveDictionary ParentDictionary { get; private set; }
|
||||
internal IDictionary RefIDict;
|
||||
|
||||
public CachePaired(int index, InteractiveDictionary parentDict, IDictionary refIDict, PairTypes pairType, GameObject parentContent)
|
||||
{
|
||||
Index = index;
|
||||
ParentDictionary = parentDict;
|
||||
RefIDict = refIDict;
|
||||
this.PairType = pairType;
|
||||
this.m_parentContent = parentContent;
|
||||
}
|
||||
|
||||
public override void CreateIValue(object value, Type fallbackType)
|
||||
{
|
||||
IValue = InteractiveValue.Create(value, fallbackType);
|
||||
IValue.Owner = this;
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal override void ConstructUI()
|
||||
{
|
||||
base.ConstructUI();
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(m_mainContent, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.padding.left = 5;
|
||||
rowGroup.padding.right = 2;
|
||||
|
||||
var indexLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
var indexLayout = indexLabelObj.AddComponent<LayoutElement>();
|
||||
indexLayout.minWidth = 80;
|
||||
indexLayout.flexibleWidth = 30;
|
||||
indexLayout.minHeight = 25;
|
||||
var indexText = indexLabelObj.GetComponent<Text>();
|
||||
indexText.text = $"{this.PairType} {this.Index}:";
|
||||
|
||||
IValue.m_mainContentParent = rowObj;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
71
src/Core/Inspectors/Reflection/CacheObject/CacheProperty.cs
Normal file
71
src/Core/Inspectors/Reflection/CacheObject/CacheProperty.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheProperty : CacheMember
|
||||
{
|
||||
public override Type FallbackType => (MemInfo as PropertyInfo).PropertyType;
|
||||
|
||||
public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors(true)[0].IsStatic;
|
||||
|
||||
public CacheProperty(PropertyInfo propertyInfo, object declaringInstance, GameObject parent) : base(propertyInfo, declaringInstance, parent)
|
||||
{
|
||||
this.m_arguments = propertyInfo.GetIndexParameters();
|
||||
this.m_argumentInput = new string[m_arguments.Length];
|
||||
|
||||
CreateIValue(null, propertyInfo.PropertyType);
|
||||
}
|
||||
|
||||
public override void UpdateReflection()
|
||||
{
|
||||
if (HasParameters && !m_isEvaluating)
|
||||
{
|
||||
// Need to enter parameters first.
|
||||
return;
|
||||
}
|
||||
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
|
||||
if (pi.CanRead)
|
||||
{
|
||||
var target = pi.GetAccessors(true)[0].IsStatic ? null : DeclaringInstance;
|
||||
|
||||
IValue.Value = pi.GetValue(target, ParseArguments());
|
||||
|
||||
m_evaluated = true;
|
||||
ReflectionException = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FallbackType == typeof(string))
|
||||
{
|
||||
IValue.Value = "";
|
||||
}
|
||||
else if (FallbackType.IsPrimitive)
|
||||
{
|
||||
IValue.Value = Activator.CreateInstance(FallbackType);
|
||||
}
|
||||
m_evaluated = true;
|
||||
ReflectionException = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||
|
||||
pi.SetValue(target, IValue.Value, ParseArguments());
|
||||
|
||||
if (this.ParentInspector?.ParentMember != null)
|
||||
this.ParentInspector.ParentMember.SetValue();
|
||||
}
|
||||
}
|
||||
}
|
54
src/Core/Inspectors/Reflection/InstanceInspector.cs
Normal file
54
src/Core/Inspectors/Reflection/InstanceInspector.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
using System.IO;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public enum MemberScopes
|
||||
{
|
||||
All,
|
||||
Instance,
|
||||
Static
|
||||
}
|
||||
|
||||
public class InstanceInspector : ReflectionInspector
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[R]</color> {base.TabLabel}";
|
||||
|
||||
internal MemberScopes m_scopeFilter;
|
||||
internal Button m_lastActiveScopeButton;
|
||||
|
||||
public InstanceInspector(object target) : base(target) { }
|
||||
|
||||
internal InstanceInspectorUI InstanceUI;
|
||||
public void CreateInstanceUIModule()
|
||||
{
|
||||
InstanceUI = new InstanceInspectorUI(this);
|
||||
}
|
||||
|
||||
internal void OnScopeFilterClicked(MemberScopes type, Button button)
|
||||
{
|
||||
if (m_lastActiveScopeButton)
|
||||
{
|
||||
var lastColors = m_lastActiveScopeButton.colors;
|
||||
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
m_lastActiveScopeButton.colors = lastColors;
|
||||
}
|
||||
|
||||
m_scopeFilter = type;
|
||||
m_lastActiveScopeButton = button;
|
||||
|
||||
var colors = m_lastActiveScopeButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_lastActiveScopeButton.colors = colors;
|
||||
|
||||
FilterMembers(null, true);
|
||||
base.ReflectionUI.m_sliderScroller.m_slider.value = 1f;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveBool : InteractiveValue
|
||||
{
|
||||
public InteractiveBool(object value, Type valueType) : base(value, valueType) { }
|
||||
|
||||
public override bool HasSubContent => false;
|
||||
public override bool SubContentWanted => false;
|
||||
public override bool WantInspectBtn => false;
|
||||
|
||||
internal Toggle m_toggle;
|
||||
internal Button m_applyBtn;
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
GetDefaultLabel();
|
||||
|
||||
if (Owner.HasEvaluated)
|
||||
{
|
||||
var val = (bool)Value;
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
if (!m_toggle.gameObject.activeSelf)
|
||||
m_toggle.gameObject.SetActive(true);
|
||||
|
||||
if (!m_applyBtn.gameObject.activeSelf)
|
||||
m_applyBtn.gameObject.SetActive(true);
|
||||
|
||||
if (val != m_toggle.isOn)
|
||||
m_toggle.isOn = val;
|
||||
}
|
||||
|
||||
var color = val
|
||||
? "6bc981" // on
|
||||
: "c96b6b"; // off
|
||||
|
||||
m_baseLabel.text = $"<color=#{color}>{val}</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnException(CacheMember member)
|
||||
{
|
||||
base.OnException(member);
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
if (m_toggle.gameObject.activeSelf)
|
||||
m_toggle.gameObject.SetActive(false);
|
||||
|
||||
if (m_applyBtn.gameObject.activeSelf)
|
||||
m_applyBtn.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnToggleValueChanged(bool val)
|
||||
{
|
||||
Value = val;
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
|
||||
var baseLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
||||
baseLayout.flexibleWidth = 0;
|
||||
baseLayout.minWidth = 50;
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var toggleObj = UIFactory.CreateToggle(m_valueContent, out m_toggle, out _, new Color(0.1f, 0.1f, 0.1f));
|
||||
var toggleLayout = toggleObj.AddComponent<LayoutElement>();
|
||||
toggleLayout.minWidth = 24;
|
||||
|
||||
m_toggle.onValueChanged.AddListener(OnToggleValueChanged);
|
||||
|
||||
m_baseLabel.transform.SetAsLastSibling();
|
||||
|
||||
var applyBtnObj = UIFactory.CreateButton(m_valueContent, new Color(0.2f, 0.2f, 0.2f));
|
||||
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||
applyLayout.minWidth = 50;
|
||||
applyLayout.minHeight = 25;
|
||||
applyLayout.flexibleWidth = 0;
|
||||
m_applyBtn = applyBtnObj.GetComponent<Button>();
|
||||
m_applyBtn.onClick.AddListener(() => { Owner.SetValue(); });
|
||||
|
||||
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||
applyText.text = "Apply";
|
||||
|
||||
toggleObj.SetActive(false);
|
||||
applyBtnObj.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,320 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using System.Reflection;
|
||||
#if CPP
|
||||
using CppDictionary = Il2CppSystem.Collections.IDictionary;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveDictionary : InteractiveValue
|
||||
{
|
||||
public InteractiveDictionary(object value, Type valueType) : base(value, valueType)
|
||||
{
|
||||
if (valueType.IsGenericType)
|
||||
{
|
||||
var gArgs = valueType.GetGenericArguments();
|
||||
m_typeOfKeys = gArgs[0];
|
||||
m_typeofValues = gArgs[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_typeOfKeys = typeof(object);
|
||||
m_typeofValues = typeof(object);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool WantInspectBtn => false;
|
||||
public override bool HasSubContent => true;
|
||||
// todo fix for il2cpp
|
||||
public override bool SubContentWanted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_recacheWanted)
|
||||
return true;
|
||||
else return m_entries.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal IDictionary RefIDictionary;
|
||||
#if CPP
|
||||
internal CppDictionary RefCppDictionary;
|
||||
#else
|
||||
internal IDictionary RefCppDictionary = null;
|
||||
#endif
|
||||
internal Type m_typeOfKeys;
|
||||
internal Type m_typeofValues;
|
||||
|
||||
internal readonly List<KeyValuePair<CachePaired, CachePaired>> m_entries
|
||||
= new List<KeyValuePair<CachePaired, CachePaired>>();
|
||||
|
||||
internal readonly KeyValuePair<CachePaired, CachePaired>[] m_displayedEntries
|
||||
= new KeyValuePair<CachePaired, CachePaired>[ExplorerConfig.Instance.Default_Page_Limit];
|
||||
|
||||
internal bool m_recacheWanted = true;
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
RefIDictionary = Value as IDictionary;
|
||||
|
||||
#if CPP
|
||||
try { RefCppDictionary = (Value as Il2CppSystem.Object).TryCast<CppDictionary>(); }
|
||||
catch { }
|
||||
#endif
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
GetCacheEntries();
|
||||
RefreshDisplay();
|
||||
}
|
||||
else
|
||||
m_recacheWanted = true;
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
internal void OnPageTurned()
|
||||
{
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
GetDefaultLabel();
|
||||
|
||||
if (Value != null)
|
||||
{
|
||||
string count = "?";
|
||||
if (m_recacheWanted && RefIDictionary != null)
|
||||
count = RefIDictionary.Count.ToString();
|
||||
else if (!m_recacheWanted)
|
||||
count = m_entries.Count.ToString();
|
||||
|
||||
m_baseLabel.text = $"[{count}] {m_richValueType}";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetCacheEntries()
|
||||
{
|
||||
if (m_entries.Any())
|
||||
{
|
||||
// maybe improve this, probably could be more efficient i guess
|
||||
|
||||
foreach (var pair in m_entries)
|
||||
{
|
||||
pair.Key.Destroy();
|
||||
pair.Value.Destroy();
|
||||
}
|
||||
|
||||
m_entries.Clear();
|
||||
}
|
||||
|
||||
#if CPP
|
||||
if (RefIDictionary == null && Value != null)
|
||||
RefIDictionary = EnumerateWithReflection();
|
||||
#endif
|
||||
|
||||
if (RefIDictionary != null)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
foreach (var key in RefIDictionary.Keys)
|
||||
{
|
||||
var value = RefIDictionary[key];
|
||||
|
||||
var cacheKey = new CachePaired(index, this, this.RefIDictionary, PairTypes.Key, m_listContent);
|
||||
cacheKey.CreateIValue(key, this.m_typeOfKeys);
|
||||
cacheKey.Disable();
|
||||
|
||||
var cacheValue = new CachePaired(index, this, this.RefIDictionary, PairTypes.Value, m_listContent);
|
||||
cacheValue.CreateIValue(value, this.m_typeofValues);
|
||||
cacheValue.Disable();
|
||||
|
||||
//holder.SetActive(false);
|
||||
|
||||
m_entries.Add(new KeyValuePair<CachePaired, CachePaired>(cacheKey, cacheValue));
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public void RefreshDisplay()
|
||||
{
|
||||
var entries = m_entries;
|
||||
m_pageHandler.ListCount = entries.Count;
|
||||
|
||||
for (int i = 0; i < m_displayedEntries.Length; i++)
|
||||
{
|
||||
var entry = m_displayedEntries[i];
|
||||
if (entry.Key != null && entry.Value != null)
|
||||
{
|
||||
//m_rowHolders[i].SetActive(false);
|
||||
entry.Key.Disable();
|
||||
entry.Value.Disable();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (entries.Count < 1)
|
||||
return;
|
||||
|
||||
foreach (var itemIndex in m_pageHandler)
|
||||
{
|
||||
if (itemIndex >= entries.Count)
|
||||
break;
|
||||
|
||||
var entry = entries[itemIndex];
|
||||
m_displayedEntries[itemIndex - m_pageHandler.StartIndex] = entry;
|
||||
|
||||
//m_rowHolders[itemIndex].SetActive(true);
|
||||
entry.Key.Enable();
|
||||
entry.Value.Enable();
|
||||
}
|
||||
|
||||
//UpdateSubcontentHeight();
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool active)
|
||||
{
|
||||
base.OnToggleSubcontent(active);
|
||||
|
||||
if (active && m_recacheWanted)
|
||||
{
|
||||
m_recacheWanted = false;
|
||||
GetCacheEntries();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
#region CPP fixes
|
||||
#if CPP
|
||||
// temp fix for Il2Cpp IDictionary until interfaces are fixed
|
||||
|
||||
private IDictionary EnumerateWithReflection()
|
||||
{
|
||||
var valueType = Value?.GetType() ?? FallbackType;
|
||||
|
||||
// get keys and values
|
||||
var keys = valueType.GetProperty("Keys").GetValue(Value, null);
|
||||
var values = valueType.GetProperty("Values").GetValue(Value, null);
|
||||
|
||||
// create lists to hold them
|
||||
var keyList = new List<object>();
|
||||
var valueList = new List<object>();
|
||||
|
||||
// store entries with reflection
|
||||
EnumerateCollection(keys, keyList);
|
||||
EnumerateCollection(values, valueList);
|
||||
|
||||
// make actual mono dictionary
|
||||
var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>)
|
||||
.MakeGenericType(m_typeOfKeys, m_typeofValues));
|
||||
|
||||
// finally iterate into mono dictionary
|
||||
for (int i = 0; i < keyList.Count; i++)
|
||||
dict.Add(keyList[i], valueList[i]);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private void EnumerateCollection(object collection, List<object> list)
|
||||
{
|
||||
// invoke GetEnumerator
|
||||
var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null);
|
||||
// get the type of it
|
||||
var enumeratorType = enumerator.GetType();
|
||||
// reflect MoveNext and Current
|
||||
var moveNext = enumeratorType.GetMethod("MoveNext");
|
||||
var current = enumeratorType.GetProperty("Current");
|
||||
// iterate
|
||||
while ((bool)moveNext.Invoke(enumerator, null))
|
||||
{
|
||||
list.Add(current.GetValue(enumerator, null));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_listContent;
|
||||
internal LayoutElement m_listLayout;
|
||||
|
||||
internal PageHandler m_pageHandler;
|
||||
|
||||
//internal List<GameObject> m_rowHolders = new List<GameObject>();
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
m_pageHandler = new PageHandler(null);
|
||||
m_pageHandler.ConstructUI(m_subContentParent);
|
||||
m_pageHandler.OnPageChanged += OnPageTurned;
|
||||
|
||||
var scrollObj = UIFactory.CreateVerticalGroup(this.m_subContentParent, new Color(0.08f, 0.08f, 0.08f));
|
||||
m_listContent = scrollObj;
|
||||
|
||||
var scrollRect = scrollObj.GetComponent<RectTransform>();
|
||||
scrollRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0);
|
||||
|
||||
m_listLayout = Owner.m_mainContent.GetComponent<LayoutElement>();
|
||||
m_listLayout.minHeight = 25;
|
||||
m_listLayout.flexibleHeight = 0;
|
||||
Owner.m_mainRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);
|
||||
|
||||
var scrollGroup = m_listContent.GetComponent<VerticalLayoutGroup>();
|
||||
scrollGroup.childForceExpandHeight = true;
|
||||
scrollGroup.SetChildControlHeight(true);
|
||||
scrollGroup.spacing = 2;
|
||||
scrollGroup.padding.top = 5;
|
||||
scrollGroup.padding.left = 5;
|
||||
scrollGroup.padding.right = 5;
|
||||
scrollGroup.padding.bottom = 5;
|
||||
|
||||
var contentFitter = scrollObj.AddComponent<ContentSizeFitter>();
|
||||
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
}
|
||||
|
||||
//internal void AddRowHolder()
|
||||
//{
|
||||
// var obj = UIFactory.CreateHorizontalGroup(m_listContent, new Color(0.15f, 0.15f, 0.15f));
|
||||
|
||||
// m_rowHolders.Add(obj);
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveEnum : InteractiveValue
|
||||
{
|
||||
internal static Dictionary<Type, KeyValuePair<int,string>[]> s_enumNamesCache = new Dictionary<Type, KeyValuePair<int, string>[]>();
|
||||
|
||||
public InteractiveEnum(object value, Type valueType) : base(value, valueType)
|
||||
{
|
||||
GetNames();
|
||||
}
|
||||
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted => Owner.CanWrite;
|
||||
public override bool WantInspectBtn => false;
|
||||
|
||||
internal KeyValuePair<int,string>[] m_values = new KeyValuePair<int, string>[0];
|
||||
|
||||
internal Type m_lastEnumType;
|
||||
|
||||
internal void GetNames()
|
||||
{
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
|
||||
if (m_lastEnumType == type)
|
||||
return;
|
||||
|
||||
m_lastEnumType = type;
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
DestroySubContent();
|
||||
}
|
||||
|
||||
if (!s_enumNamesCache.ContainsKey(type))
|
||||
{
|
||||
// using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags)
|
||||
var values = Enum.GetValues(type);
|
||||
|
||||
var list = new List<KeyValuePair<int, string>>();
|
||||
var set = new HashSet<string>();
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
var name = value.ToString();
|
||||
|
||||
if (set.Contains(name))
|
||||
continue;
|
||||
|
||||
set.Add(name);
|
||||
|
||||
var backingType = Enum.GetUnderlyingType(type);
|
||||
int intValue;
|
||||
try
|
||||
{
|
||||
// this approach is necessary, a simple '(int)value' is not sufficient.
|
||||
|
||||
var unbox = Convert.ChangeType(value, backingType);
|
||||
|
||||
intValue = (int)Convert.ChangeType(unbox, typeof(int));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExplorerCore.LogWarning("[InteractiveEnum] Could not Unbox underlying type " + backingType.Name + " from " + type.FullName);
|
||||
ExplorerCore.Log(ex.ToString());
|
||||
continue;
|
||||
}
|
||||
|
||||
list.Add(new KeyValuePair<int, string>(intValue, name));
|
||||
}
|
||||
|
||||
s_enumNamesCache.Add(type, list.ToArray());
|
||||
}
|
||||
|
||||
m_values = s_enumNamesCache[type];
|
||||
}
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
GetNames();
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
m_dropdownText.text = Value?.ToString() ?? "<no value set>";
|
||||
}
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool toggle)
|
||||
{
|
||||
base.OnToggleSubcontent(toggle);
|
||||
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
private void SetValueFromDropdown()
|
||||
{
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
var index = m_dropdown.value;
|
||||
|
||||
var value = Enum.Parse(type, s_enumNamesCache[type][index].Value);
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
Value = value;
|
||||
Owner.SetValue();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
}
|
||||
|
||||
internal Dropdown m_dropdown;
|
||||
internal Text m_dropdownText;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var groupObj = UIFactory.CreateHorizontalGroup(m_subContentParent, new Color(1, 1, 1, 0));
|
||||
var group = groupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
group.padding.top = 3;
|
||||
group.padding.left = 3;
|
||||
group.padding.right = 3;
|
||||
group.padding.bottom = 3;
|
||||
group.spacing = 5;
|
||||
|
||||
// apply button
|
||||
|
||||
var applyObj = UIFactory.CreateButton(groupObj, new Color(0.3f, 0.3f, 0.3f));
|
||||
var applyLayout = applyObj.AddComponent<LayoutElement>();
|
||||
applyLayout.minHeight = 25;
|
||||
applyLayout.minWidth = 50;
|
||||
var applyText = applyObj.GetComponentInChildren<Text>();
|
||||
applyText.text = "Apply";
|
||||
var applyBtn = applyObj.GetComponent<Button>();
|
||||
applyBtn.onClick.AddListener(SetValueFromDropdown);
|
||||
|
||||
// dropdown
|
||||
|
||||
var dropdownObj = UIFactory.CreateDropdown(groupObj, out m_dropdown);
|
||||
var dropLayout = dropdownObj.AddComponent<LayoutElement>();
|
||||
dropLayout.minWidth = 150;
|
||||
dropLayout.minHeight = 25;
|
||||
dropLayout.flexibleWidth = 120;
|
||||
|
||||
foreach (var kvp in m_values)
|
||||
{
|
||||
m_dropdown.options.Add(new Dropdown.OptionData
|
||||
{
|
||||
text = $"{kvp.Key}: {kvp.Value}"
|
||||
});
|
||||
}
|
||||
|
||||
m_dropdownText = m_dropdown.transform.Find("Label").GetComponent<Text>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,287 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveEnumerable : InteractiveValue
|
||||
{
|
||||
public InteractiveEnumerable(object value, Type valueType) : base(value, valueType)
|
||||
{
|
||||
if (valueType.IsGenericType)
|
||||
m_baseEntryType = valueType.GetGenericArguments()[0];
|
||||
else
|
||||
m_baseEntryType = typeof(object);
|
||||
}
|
||||
|
||||
public override bool WantInspectBtn => false;
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_recacheWanted)
|
||||
return true;
|
||||
else return m_entries.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal IEnumerable RefIEnumerable;
|
||||
internal IList RefIList;
|
||||
#if CPP
|
||||
internal Il2CppSystem.Collections.ICollection CppICollection;
|
||||
#else
|
||||
internal ICollection CppICollection = null;
|
||||
#endif
|
||||
|
||||
internal readonly Type m_baseEntryType;
|
||||
|
||||
internal readonly List<CacheEnumerated> m_entries = new List<CacheEnumerated>();
|
||||
internal readonly CacheEnumerated[] m_displayedEntries = new CacheEnumerated[ExplorerConfig.Instance.Default_Page_Limit];
|
||||
internal bool m_recacheWanted = true;
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
RefIEnumerable = Value as IEnumerable;
|
||||
RefIList = Value as IList;
|
||||
|
||||
#if CPP
|
||||
if (Value != null && RefIList == null)
|
||||
{
|
||||
try { CppICollection = (Value as Il2CppSystem.Object).TryCast<Il2CppSystem.Collections.ICollection>(); }
|
||||
catch { }
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
GetCacheEntries();
|
||||
RefreshDisplay();
|
||||
}
|
||||
else
|
||||
m_recacheWanted = true;
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
public override void OnException(CacheMember member)
|
||||
{
|
||||
base.OnException(member);
|
||||
}
|
||||
|
||||
private void OnPageTurned()
|
||||
{
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
GetDefaultLabel();
|
||||
|
||||
if (Value != null)
|
||||
{
|
||||
string count = "?";
|
||||
if (m_recacheWanted && (RefIList != null || CppICollection != null))
|
||||
count = RefIList?.Count.ToString() ?? CppICollection.Count.ToString();
|
||||
else if (!m_recacheWanted)
|
||||
count = m_entries.Count.ToString();
|
||||
|
||||
m_baseLabel.text = $"[{count}] {m_richValueType}";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetCacheEntries()
|
||||
{
|
||||
if (m_entries.Any())
|
||||
{
|
||||
// maybe improve this, probably could be more efficient i guess
|
||||
|
||||
foreach (var entry in m_entries)
|
||||
entry.Destroy();
|
||||
|
||||
m_entries.Clear();
|
||||
}
|
||||
|
||||
#if CPP
|
||||
if (RefIEnumerable == null && Value != null)
|
||||
RefIEnumerable = EnumerateWithReflection();
|
||||
#endif
|
||||
|
||||
if (RefIEnumerable != null)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var entry in RefIEnumerable)
|
||||
{
|
||||
var cache = new CacheEnumerated(index, this, RefIList, this.m_listContent);
|
||||
cache.CreateIValue(entry, m_baseEntryType);
|
||||
m_entries.Add(cache);
|
||||
|
||||
cache.Disable();
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public void RefreshDisplay()
|
||||
{
|
||||
var entries = m_entries;
|
||||
m_pageHandler.ListCount = entries.Count;
|
||||
|
||||
for (int i = 0; i < m_displayedEntries.Length; i++)
|
||||
{
|
||||
var entry = m_displayedEntries[i];
|
||||
if (entry != null)
|
||||
entry.Disable();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (entries.Count < 1)
|
||||
return;
|
||||
|
||||
foreach (var itemIndex in m_pageHandler)
|
||||
{
|
||||
if (itemIndex >= entries.Count)
|
||||
break;
|
||||
|
||||
CacheEnumerated entry = entries[itemIndex];
|
||||
m_displayedEntries[itemIndex - m_pageHandler.StartIndex] = entry;
|
||||
entry.Enable();
|
||||
}
|
||||
|
||||
//UpdateSubcontentHeight();
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool active)
|
||||
{
|
||||
base.OnToggleSubcontent(active);
|
||||
|
||||
if (active && m_recacheWanted)
|
||||
{
|
||||
m_recacheWanted = false;
|
||||
GetCacheEntries();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
#region CPP Helpers
|
||||
|
||||
#if CPP
|
||||
// some temp fixes for Il2Cpp IEnumerables until interfaces are fixed
|
||||
|
||||
internal static readonly Dictionary<Type, MethodInfo> s_getEnumeratorMethods = new Dictionary<Type, MethodInfo>();
|
||||
|
||||
internal static readonly Dictionary<Type, EnumeratorInfo> s_enumeratorInfos = new Dictionary<Type, EnumeratorInfo>();
|
||||
|
||||
internal class EnumeratorInfo
|
||||
{
|
||||
internal MethodInfo moveNext;
|
||||
internal PropertyInfo current;
|
||||
}
|
||||
|
||||
private IEnumerable EnumerateWithReflection()
|
||||
{
|
||||
if (Value == null)
|
||||
return null;
|
||||
|
||||
// new test
|
||||
var CppEnumerable = (Value as Il2CppSystem.Object)?.TryCast<Il2CppSystem.Collections.IEnumerable>();
|
||||
if (CppEnumerable != null)
|
||||
{
|
||||
var type = Value.GetType();
|
||||
if (!s_getEnumeratorMethods.ContainsKey(type))
|
||||
s_getEnumeratorMethods.Add(type, type.GetMethod("GetEnumerator"));
|
||||
|
||||
var enumerator = s_getEnumeratorMethods[type].Invoke(Value, null);
|
||||
var enumeratorType = enumerator.GetType();
|
||||
|
||||
if (!s_enumeratorInfos.ContainsKey(enumeratorType))
|
||||
{
|
||||
s_enumeratorInfos.Add(enumeratorType, new EnumeratorInfo
|
||||
{
|
||||
current = enumeratorType.GetProperty("Current"),
|
||||
moveNext = enumeratorType.GetMethod("MoveNext"),
|
||||
});
|
||||
}
|
||||
var info = s_enumeratorInfos[enumeratorType];
|
||||
|
||||
// iterate
|
||||
var list = new List<object>();
|
||||
while ((bool)info.moveNext.Invoke(enumerator, null))
|
||||
list.Add(info.current.GetValue(enumerator));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_listContent;
|
||||
internal LayoutElement m_listLayout;
|
||||
|
||||
internal PageHandler m_pageHandler;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
m_pageHandler = new PageHandler(null);
|
||||
m_pageHandler.ConstructUI(m_subContentParent);
|
||||
m_pageHandler.OnPageChanged += OnPageTurned;
|
||||
|
||||
var scrollObj = UIFactory.CreateVerticalGroup(this.m_subContentParent, new Color(0.08f, 0.08f, 0.08f));
|
||||
m_listContent = scrollObj;
|
||||
|
||||
var scrollRect = scrollObj.GetComponent<RectTransform>();
|
||||
scrollRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0);
|
||||
|
||||
m_listLayout = Owner.m_mainContent.GetComponent<LayoutElement>();
|
||||
m_listLayout.minHeight = 25;
|
||||
m_listLayout.flexibleHeight = 0;
|
||||
Owner.m_mainRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);
|
||||
|
||||
var scrollGroup = m_listContent.GetComponent<VerticalLayoutGroup>();
|
||||
scrollGroup.childForceExpandHeight = true;
|
||||
scrollGroup.SetChildControlHeight(true);
|
||||
scrollGroup.spacing = 2;
|
||||
scrollGroup.padding.top = 5;
|
||||
scrollGroup.padding.left = 5;
|
||||
scrollGroup.padding.right = 5;
|
||||
scrollGroup.padding.bottom = 5;
|
||||
|
||||
var contentFitter = scrollObj.AddComponent<ContentSizeFitter>();
|
||||
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveFlags : InteractiveEnum
|
||||
{
|
||||
public InteractiveFlags(object value, Type valueType) : base(value, valueType)
|
||||
{
|
||||
m_toggles = new Toggle[m_values.Length];
|
||||
m_enabledFlags = new bool[m_values.Length];
|
||||
}
|
||||
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted => Owner.CanWrite;
|
||||
public override bool WantInspectBtn => false;
|
||||
|
||||
internal bool[] m_enabledFlags;
|
||||
internal Toggle[] m_toggles;
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
base.OnValueUpdated();
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var enabledNames = new List<string>();
|
||||
|
||||
var enabled = Value?.ToString().Split(',').Select(it => it.Trim());
|
||||
if (enabled != null)
|
||||
enabledNames.AddRange(enabled);
|
||||
|
||||
for (int i = 0; i < m_values.Length; i++)
|
||||
{
|
||||
m_enabledFlags[i] = enabledNames.Contains(m_values[i].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
GetDefaultLabel();
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
for (int i = 0; i < m_values.Length; i++)
|
||||
{
|
||||
var toggle = m_toggles[i];
|
||||
if (toggle.isOn != m_enabledFlags[i])
|
||||
toggle.isOn = m_enabledFlags[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValueFromToggles()
|
||||
{
|
||||
string val = "";
|
||||
for (int i = 0; i < m_values.Length; i++)
|
||||
{
|
||||
if (m_enabledFlags[i])
|
||||
{
|
||||
if (val != "") val += ", ";
|
||||
val += m_values[i].Value;
|
||||
}
|
||||
}
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
Value = Enum.Parse(type, val);
|
||||
RefreshUIForValue();
|
||||
Owner.SetValue();
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool toggle)
|
||||
{
|
||||
base.OnToggleSubcontent(toggle);
|
||||
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
m_subContentConstructed = true;
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var groupObj = UIFactory.CreateVerticalGroup(m_subContentParent, new Color(1, 1, 1, 0));
|
||||
var group = groupObj.GetComponent<VerticalLayoutGroup>();
|
||||
group.childForceExpandHeight = true;
|
||||
group.childForceExpandWidth = false;
|
||||
group.SetChildControlHeight(true);
|
||||
group.SetChildControlWidth(true);
|
||||
group.padding.top = 3;
|
||||
group.padding.left = 3;
|
||||
group.padding.right = 3;
|
||||
group.padding.bottom = 3;
|
||||
group.spacing = 5;
|
||||
|
||||
// apply button
|
||||
|
||||
var applyObj = UIFactory.CreateButton(groupObj, new Color(0.3f, 0.3f, 0.3f));
|
||||
var applyLayout = applyObj.AddComponent<LayoutElement>();
|
||||
applyLayout.minHeight = 25;
|
||||
applyLayout.minWidth = 50;
|
||||
var applyText = applyObj.GetComponentInChildren<Text>();
|
||||
applyText.text = "Apply";
|
||||
var applyBtn = applyObj.GetComponent<Button>();
|
||||
applyBtn.onClick.AddListener(SetValueFromToggles);
|
||||
|
||||
// toggles
|
||||
|
||||
for (int i = 0; i < m_values.Length; i++)
|
||||
{
|
||||
AddToggle(i, groupObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddToggle(int index, GameObject groupObj)
|
||||
{
|
||||
var value = m_values[index];
|
||||
|
||||
var toggleObj = UIFactory.CreateToggle(groupObj, out Toggle toggle, out Text text, new Color(0.1f, 0.1f, 0.1f));
|
||||
var toggleLayout = toggleObj.AddComponent<LayoutElement>();
|
||||
toggleLayout.minWidth = 100;
|
||||
toggleLayout.flexibleWidth = 2000;
|
||||
toggleLayout.minHeight = 25;
|
||||
|
||||
m_toggles[index] = toggle;
|
||||
|
||||
toggle.onValueChanged.AddListener((bool val) => { m_enabledFlags[index] = val; });
|
||||
|
||||
text.text = $"{value.Key}: {value.Value}";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveNumber : InteractiveValue
|
||||
{
|
||||
public InteractiveNumber(object value, Type valueType) : base(value, valueType) { }
|
||||
|
||||
public override bool HasSubContent => false;
|
||||
public override bool SubContentWanted => false;
|
||||
public override bool WantInspectBtn => false;
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
public override void OnException(CacheMember member)
|
||||
{
|
||||
base.OnException(member);
|
||||
|
||||
if (m_valueInput.gameObject.activeSelf)
|
||||
m_valueInput.gameObject.SetActive(false);
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
if (m_applyBtn.gameObject.activeSelf)
|
||||
m_applyBtn.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
if (!Owner.HasEvaluated)
|
||||
{
|
||||
GetDefaultLabel();
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
return;
|
||||
}
|
||||
|
||||
m_baseLabel.text = SignatureHighlighter.ParseFullSyntax(FallbackType, false);
|
||||
m_valueInput.text = Value.ToString();
|
||||
|
||||
var type = Value.GetType();
|
||||
if (type == typeof(float)
|
||||
|| type == typeof(double)
|
||||
|| type == typeof(decimal))
|
||||
{
|
||||
m_valueInput.characterValidation = InputField.CharacterValidation.Decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_valueInput.characterValidation = InputField.CharacterValidation.Integer;
|
||||
}
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
if (!m_applyBtn.gameObject.activeSelf)
|
||||
m_applyBtn.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (!m_valueInput.gameObject.activeSelf)
|
||||
m_valueInput.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }));
|
||||
private MethodInfo m_parseMethod;
|
||||
|
||||
internal void OnApplyClicked()
|
||||
{
|
||||
try
|
||||
{
|
||||
Value = ParseMethod.Invoke(null, new object[] { m_valueInput.text });
|
||||
Owner.SetValue();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not parse input! " + ReflectionUtility.ReflectionExToString(e, true));
|
||||
}
|
||||
}
|
||||
|
||||
internal InputField m_valueInput;
|
||||
internal Button m_applyBtn;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
|
||||
var labelLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
||||
labelLayout.minWidth = 50;
|
||||
labelLayout.flexibleWidth = 0;
|
||||
|
||||
var inputObj = UIFactory.CreateInputField(m_valueContent);
|
||||
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
||||
inputLayout.minWidth = 120;
|
||||
inputLayout.minHeight = 25;
|
||||
inputLayout.flexibleWidth = 0;
|
||||
|
||||
m_valueInput = inputObj.GetComponent<InputField>();
|
||||
m_valueInput.gameObject.SetActive(false);
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var applyBtnObj = UIFactory.CreateButton(m_valueContent, new Color(0.2f, 0.2f, 0.2f));
|
||||
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||
applyLayout.minWidth = 50;
|
||||
applyLayout.minHeight = 25;
|
||||
applyLayout.flexibleWidth = 0;
|
||||
m_applyBtn = applyBtnObj.GetComponent<Button>();
|
||||
m_applyBtn.onClick.AddListener(OnApplyClicked);
|
||||
|
||||
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||
applyText.text = "Apply";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveString : InteractiveValue
|
||||
{
|
||||
public InteractiveString(object value, Type valueType) : base(value, valueType) { }
|
||||
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted => true;
|
||||
|
||||
public override bool WantInspectBtn => false;
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
public override void OnException(CacheMember member)
|
||||
{
|
||||
base.OnException(member);
|
||||
|
||||
if (m_subContentConstructed && m_hiddenObj.gameObject.activeSelf)
|
||||
m_hiddenObj.gameObject.SetActive(false);
|
||||
|
||||
m_labelLayout.minWidth = 200;
|
||||
m_labelLayout.flexibleWidth = 5000;
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
GetDefaultLabel(false);
|
||||
|
||||
if (!Owner.HasEvaluated)
|
||||
{
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
return;
|
||||
}
|
||||
|
||||
m_baseLabel.text = m_richValueType;
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
if (!m_hiddenObj.gameObject.activeSelf)
|
||||
m_hiddenObj.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty((string)Value))
|
||||
{
|
||||
var toString = (string)Value;
|
||||
if (toString.Length > 15000)
|
||||
toString = toString.Substring(0, 15000);
|
||||
|
||||
m_readonlyInput.text = toString;
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
m_valueInput.text = toString;
|
||||
m_placeholderText.text = toString;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string s = Value == null
|
||||
? "null"
|
||||
: "empty";
|
||||
|
||||
m_readonlyInput.text = $"<i><color=grey>{s}</color></i>";
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
m_valueInput.text = "";
|
||||
m_placeholderText.text = s;
|
||||
}
|
||||
}
|
||||
|
||||
m_labelLayout.minWidth = 50;
|
||||
m_labelLayout.flexibleWidth = 0;
|
||||
}
|
||||
|
||||
internal void OnApplyClicked()
|
||||
{
|
||||
Value = m_valueInput.text;
|
||||
Owner.SetValue();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
// for the default label
|
||||
internal LayoutElement m_labelLayout;
|
||||
|
||||
//internal InputField m_readonlyInput;
|
||||
internal Text m_readonlyInput;
|
||||
|
||||
// for input
|
||||
internal InputField m_valueInput;
|
||||
internal GameObject m_hiddenObj;
|
||||
internal Text m_placeholderText;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
|
||||
GetDefaultLabel(false);
|
||||
m_richValueType = SignatureHighlighter.ParseFullSyntax(FallbackType, false);
|
||||
|
||||
m_labelLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
||||
|
||||
var readonlyInputObj = UIFactory.CreateLabel(m_valueContent, TextAnchor.MiddleLeft);
|
||||
m_readonlyInput = readonlyInputObj.GetComponent<Text>();
|
||||
m_readonlyInput.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
|
||||
var testFitter = readonlyInputObj.AddComponent<ContentSizeFitter>();
|
||||
testFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;
|
||||
|
||||
var labelLayout = readonlyInputObj.AddComponent<LayoutElement>();
|
||||
labelLayout.minHeight = 25;
|
||||
labelLayout.preferredHeight = 25;
|
||||
labelLayout.flexibleHeight = 0;
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
var groupObj = UIFactory.CreateVerticalGroup(m_subContentParent, new Color(1, 1, 1, 0));
|
||||
var group = groupObj.GetComponent<VerticalLayoutGroup>();
|
||||
group.spacing = 4;
|
||||
group.padding.top = 3;
|
||||
group.padding.left = 3;
|
||||
group.padding.right = 3;
|
||||
group.padding.bottom = 3;
|
||||
|
||||
m_hiddenObj = UIFactory.CreateLabel(groupObj, TextAnchor.MiddleLeft);
|
||||
m_hiddenObj.SetActive(false);
|
||||
var hiddenText = m_hiddenObj.GetComponent<Text>();
|
||||
hiddenText.color = Color.clear;
|
||||
hiddenText.fontSize = 14;
|
||||
hiddenText.raycastTarget = false;
|
||||
hiddenText.supportRichText = false;
|
||||
var hiddenFitter = m_hiddenObj.AddComponent<ContentSizeFitter>();
|
||||
hiddenFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
var hiddenLayout = m_hiddenObj.AddComponent<LayoutElement>();
|
||||
hiddenLayout.minHeight = 25;
|
||||
hiddenLayout.flexibleHeight = 500;
|
||||
hiddenLayout.minWidth = 250;
|
||||
hiddenLayout.flexibleWidth = 9000;
|
||||
var hiddenGroup = m_hiddenObj.AddComponent<HorizontalLayoutGroup>();
|
||||
hiddenGroup.childForceExpandWidth = true;
|
||||
hiddenGroup.SetChildControlWidth(true);
|
||||
hiddenGroup.childForceExpandHeight = true;
|
||||
hiddenGroup.SetChildControlHeight(true);
|
||||
|
||||
var inputObj = UIFactory.CreateInputField(m_hiddenObj, 14, 3);
|
||||
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
||||
inputLayout.minWidth = 120;
|
||||
inputLayout.minHeight = 25;
|
||||
inputLayout.flexibleWidth = 5000;
|
||||
inputLayout.flexibleHeight = 5000;
|
||||
|
||||
m_valueInput = inputObj.GetComponent<InputField>();
|
||||
m_valueInput.lineType = InputField.LineType.MultiLineNewline;
|
||||
|
||||
m_placeholderText = m_valueInput.placeholder.GetComponent<Text>();
|
||||
|
||||
m_placeholderText.supportRichText = false;
|
||||
m_valueInput.textComponent.supportRichText = false;
|
||||
|
||||
m_valueInput.onValueChanged.AddListener((string val) =>
|
||||
{
|
||||
hiddenText.text = val ?? "";
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(Owner.m_mainRect);
|
||||
});
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var applyBtnObj = UIFactory.CreateButton(groupObj, new Color(0.2f, 0.2f, 0.2f));
|
||||
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||
applyLayout.minWidth = 50;
|
||||
applyLayout.minHeight = 25;
|
||||
applyLayout.flexibleWidth = 0;
|
||||
|
||||
var applyBtn = applyBtnObj.GetComponent<Button>();
|
||||
applyBtn.onClick.AddListener(OnApplyClicked);
|
||||
|
||||
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||
applyText.text = "Apply";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_valueInput.readOnly = true;
|
||||
}
|
||||
|
||||
RefreshUIForValue();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,338 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
#region IStructInfo helper
|
||||
|
||||
public interface IStructInfo
|
||||
{
|
||||
string[] FieldNames { get; }
|
||||
object SetValue(ref object value, int fieldIndex, float val);
|
||||
void RefreshUI(InputField[] inputs, object value);
|
||||
}
|
||||
|
||||
public class StructInfo<T> : IStructInfo where T : struct
|
||||
{
|
||||
public string[] FieldNames { get; set; }
|
||||
|
||||
public delegate void SetMethod(ref T value, int fieldIndex, float val);
|
||||
public SetMethod SetValueMethod;
|
||||
|
||||
public delegate void UpdateMethod(InputField[] inputs, object value);
|
||||
public UpdateMethod UpdateUIMethod;
|
||||
|
||||
public object SetValue(ref object value, int fieldIndex, float val)
|
||||
{
|
||||
var box = (T)value;
|
||||
SetValueMethod.Invoke(ref box, fieldIndex, val);
|
||||
return box;
|
||||
}
|
||||
|
||||
public void RefreshUI(InputField[] inputs, object value)
|
||||
{
|
||||
UpdateUIMethod.Invoke(inputs, value);
|
||||
}
|
||||
}
|
||||
|
||||
// This part is a bit ugly, but everything else is generalized above.
|
||||
// I could generalize it more with reflection, but it would be different for
|
||||
// mono/il2cpp and also slower.
|
||||
public static class StructInfoFactory
|
||||
{
|
||||
public static IStructInfo Create(Type type)
|
||||
{
|
||||
if (type == typeof(Vector2))
|
||||
{
|
||||
return new StructInfo<Vector2>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", },
|
||||
SetValueMethod = (ref Vector2 vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Vector2 vec = (Vector2)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Vector3))
|
||||
{
|
||||
return new StructInfo<Vector3>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", "z" },
|
||||
SetValueMethod = (ref Vector3 vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
case 2: vec.z = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Vector3 vec = (Vector3)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
inputs[2].text = vec.z.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Vector4))
|
||||
{
|
||||
return new StructInfo<Vector4>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", "z", "w" },
|
||||
SetValueMethod = (ref Vector4 vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
case 2: vec.z = val; break;
|
||||
case 3: vec.w = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Vector4 vec = (Vector4)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
inputs[2].text = vec.z.ToString();
|
||||
inputs[3].text = vec.w.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Rect))
|
||||
{
|
||||
return new StructInfo<Rect>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", "width", "height" },
|
||||
SetValueMethod = (ref Rect vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
case 2: vec.width = val; break;
|
||||
case 3: vec.height = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Rect vec = (Rect)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
inputs[2].text = vec.width.ToString();
|
||||
inputs[3].text = vec.height.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Color))
|
||||
{
|
||||
return new StructInfo<Color>()
|
||||
{
|
||||
FieldNames = new[] { "r", "g", "b", "a" },
|
||||
SetValueMethod = (ref Color vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.r = val; break;
|
||||
case 1: vec.g = val; break;
|
||||
case 2: vec.b = val; break;
|
||||
case 3: vec.a = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Color vec = (Color)value;
|
||||
inputs[0].text = vec.r.ToString();
|
||||
inputs[1].text = vec.g.ToString();
|
||||
inputs[2].text = vec.b.ToString();
|
||||
inputs[3].text = vec.a.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public class InteractiveUnityStruct : InteractiveValue
|
||||
{
|
||||
public static bool SupportsType(Type type) => s_supportedTypes.Contains(type);
|
||||
private static readonly HashSet<Type> s_supportedTypes = new HashSet<Type>
|
||||
{
|
||||
typeof(Vector2),
|
||||
typeof(Vector3),
|
||||
typeof(Vector4),
|
||||
typeof(Rect),
|
||||
typeof(Color) // todo might make a special editor for colors
|
||||
};
|
||||
|
||||
//~~~~~~~~~ Instance ~~~~~~~~~~
|
||||
|
||||
public InteractiveUnityStruct(object value, Type valueType) : base(value, valueType) { }
|
||||
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted => true;
|
||||
public override bool WantInspectBtn => true;
|
||||
|
||||
public IStructInfo StructInfo;
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool toggle)
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.OnToggleSubcontent(toggle);
|
||||
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
internal Type m_lastStructType;
|
||||
|
||||
internal void InitializeStructInfo()
|
||||
{
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
|
||||
if (StructInfo != null && type == m_lastStructType)
|
||||
return;
|
||||
|
||||
if (StructInfo != null)
|
||||
{
|
||||
DestroySubContent();
|
||||
//// changing types, destroy subcontent
|
||||
//for (int i = 0; i < m_subContentParent.transform.childCount; i++)
|
||||
//{
|
||||
// var child = m_subContentParent.transform.GetChild(i);
|
||||
// GameObject.Destroy(child.gameObject);
|
||||
//}
|
||||
|
||||
//m_UIConstructed = false;
|
||||
}
|
||||
|
||||
m_lastStructType = type;
|
||||
|
||||
StructInfo = StructInfoFactory.Create(type);
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
ConstructSubcontent();
|
||||
}
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal InputField[] m_inputs;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
if (StructInfo == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Setting up subcontent but structinfo is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var editorContainer = UIFactory.CreateVerticalGroup(m_subContentParent, new Color(0.08f, 0.08f, 0.08f));
|
||||
var editorGroup = editorContainer.GetComponent<VerticalLayoutGroup>();
|
||||
editorGroup.childForceExpandWidth = false;
|
||||
editorGroup.padding.top = 4;
|
||||
editorGroup.padding.right = 4;
|
||||
editorGroup.padding.left = 4;
|
||||
editorGroup.padding.bottom = 4;
|
||||
editorGroup.spacing = 2;
|
||||
|
||||
m_inputs = new InputField[StructInfo.FieldNames.Length];
|
||||
|
||||
for (int i = 0; i < StructInfo.FieldNames.Length; i++)
|
||||
{
|
||||
AddEditorRow(i, editorContainer);
|
||||
}
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var applyBtnObj = UIFactory.CreateButton(editorContainer, new Color(0.2f, 0.2f, 0.2f));
|
||||
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||
applyLayout.minWidth = 175;
|
||||
applyLayout.minHeight = 25;
|
||||
applyLayout.flexibleWidth = 0;
|
||||
var m_applyBtn = applyBtnObj.GetComponent<Button>();
|
||||
m_applyBtn.onClick.AddListener(OnSetValue);
|
||||
|
||||
void OnSetValue()
|
||||
{
|
||||
Owner.SetValue();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||
applyText.text = "Apply";
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddEditorRow(int index, GameObject groupObj)
|
||||
{
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(groupObj, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childForceExpandHeight = true;
|
||||
rowGroup.childForceExpandWidth = false;
|
||||
rowGroup.spacing = 5;
|
||||
|
||||
var label = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleRight);
|
||||
var labelLayout = label.AddComponent<LayoutElement>();
|
||||
labelLayout.minWidth = 50;
|
||||
labelLayout.flexibleWidth = 0;
|
||||
labelLayout.minHeight = 25;
|
||||
var labelText = label.GetComponent<Text>();
|
||||
labelText.text = $"{StructInfo.FieldNames[index]}:";
|
||||
labelText.color = Color.cyan;
|
||||
|
||||
var inputFieldObj = UIFactory.CreateInputField(rowObj, 14, 3, 1);
|
||||
var inputField = inputFieldObj.GetComponent<InputField>();
|
||||
inputField.characterValidation = InputField.CharacterValidation.Decimal;
|
||||
var inputLayout = inputFieldObj.AddComponent<LayoutElement>();
|
||||
inputLayout.flexibleWidth = 0;
|
||||
inputLayout.minWidth = 120;
|
||||
inputLayout.minHeight = 25;
|
||||
|
||||
m_inputs[index] = inputField;
|
||||
|
||||
inputField.onValueChanged.AddListener((string val) => { Value = StructInfo.SetValue(ref this.Value, index, float.Parse(val)); });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,374 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveValue
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the <see cref="InteractiveValue"/> subclass which supports the provided <paramref name="type"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">The <see cref="Type"/> which you want the <see cref="InteractiveValue"/> Type for.</param>
|
||||
/// <returns>The best subclass of <see cref="InteractiveValue"/> which supports the provided <paramref name="type"/>.</returns>
|
||||
public static Type GetIValueForType(Type type)
|
||||
{
|
||||
// rather ugly but I couldn't think of a cleaner way that was worth it.
|
||||
// switch-case doesn't really work here.
|
||||
|
||||
// arbitrarily check some types, fastest methods first.
|
||||
if (type == typeof(bool))
|
||||
return typeof(InteractiveBool);
|
||||
// if type is primitive then it must be a number if its not a bool
|
||||
else if (type.IsPrimitive)
|
||||
return typeof(InteractiveNumber);
|
||||
// check for strings
|
||||
else if (type == typeof(string))
|
||||
return typeof(InteractiveString);
|
||||
// check for enum/flags
|
||||
else if (typeof(Enum).IsAssignableFrom(type))
|
||||
{
|
||||
// NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version.
|
||||
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Any())
|
||||
return typeof(InteractiveFlags);
|
||||
else
|
||||
return typeof(InteractiveEnum);
|
||||
}
|
||||
// check for unity struct types
|
||||
else if (InteractiveUnityStruct.SupportsType(type))
|
||||
return typeof(InteractiveUnityStruct);
|
||||
// check Transform, force InteractiveValue so they dont become InteractiveEnumerables.
|
||||
else if (typeof(Transform).IsAssignableFrom(type))
|
||||
return typeof(InteractiveValue);
|
||||
// check Dictionaries before Enumerables
|
||||
else if (ReflectionUtility.IsDictionary(type))
|
||||
return typeof(InteractiveDictionary);
|
||||
// finally check for Enumerables
|
||||
else if (ReflectionUtility.IsEnumerable(type))
|
||||
return typeof(InteractiveEnumerable);
|
||||
// fallback to default
|
||||
else
|
||||
return typeof(InteractiveValue);
|
||||
}
|
||||
|
||||
public static InteractiveValue Create(object value, Type fallbackType)
|
||||
{
|
||||
var type = ReflectionUtility.GetType(value) ?? fallbackType;
|
||||
var iType = GetIValueForType(type);
|
||||
|
||||
return (InteractiveValue)Activator.CreateInstance(iType, new object[] { value, type });
|
||||
}
|
||||
|
||||
// ~~~~~~~~~ Instance ~~~~~~~~~
|
||||
|
||||
public InteractiveValue(object value, Type valueType)
|
||||
{
|
||||
this.Value = value;
|
||||
this.FallbackType = valueType;
|
||||
}
|
||||
|
||||
public CacheObjectBase Owner;
|
||||
|
||||
public object Value;
|
||||
public readonly Type FallbackType;
|
||||
|
||||
public virtual bool HasSubContent => false;
|
||||
public virtual bool SubContentWanted => false;
|
||||
public virtual bool WantInspectBtn => true;
|
||||
|
||||
public string DefaultLabel => m_defaultLabel ?? GetDefaultLabel();
|
||||
internal string m_defaultLabel;
|
||||
internal string m_richValueType;
|
||||
|
||||
public bool m_UIConstructed;
|
||||
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
if (this.m_valueContent)
|
||||
{
|
||||
m_valueContent.transform.SetParent(null, false);
|
||||
m_valueContent.SetActive(false);
|
||||
GameObject.Destroy(this.m_valueContent.gameObject);
|
||||
}
|
||||
|
||||
DestroySubContent();
|
||||
}
|
||||
|
||||
public virtual void DestroySubContent()
|
||||
{
|
||||
if (this.m_subContentParent && HasSubContent)
|
||||
{
|
||||
for (int i = 0; i < this.m_subContentParent.transform.childCount; i++)
|
||||
{
|
||||
var child = m_subContentParent.transform.GetChild(i);
|
||||
if (child)
|
||||
GameObject.Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
m_subContentConstructed = false;
|
||||
}
|
||||
|
||||
public virtual void OnValueUpdated()
|
||||
{
|
||||
if (!m_UIConstructed)
|
||||
ConstructUI(m_mainContentParent, m_subContentParent);
|
||||
|
||||
if (Owner is CacheMember ownerMember && !string.IsNullOrEmpty(ownerMember.ReflectionException))
|
||||
OnException(ownerMember);
|
||||
else
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
public virtual void OnException(CacheMember member)
|
||||
{
|
||||
if (m_UIConstructed)
|
||||
m_baseLabel.text = "<color=red>" + member.ReflectionException + "</color>";
|
||||
|
||||
Value = null;
|
||||
}
|
||||
|
||||
public virtual void RefreshUIForValue()
|
||||
{
|
||||
GetDefaultLabel();
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
}
|
||||
|
||||
public void RefreshElementsAfterUpdate()
|
||||
{
|
||||
if (WantInspectBtn)
|
||||
{
|
||||
bool shouldShowInspect = !Value.IsNullOrDestroyed();
|
||||
|
||||
if (m_inspectButton.activeSelf != shouldShowInspect)
|
||||
m_inspectButton.SetActive(shouldShowInspect);
|
||||
}
|
||||
|
||||
bool subContentWanted = SubContentWanted;
|
||||
if (Owner is CacheMember cm && (!cm.HasEvaluated || !string.IsNullOrEmpty(cm.ReflectionException)))
|
||||
subContentWanted = false;
|
||||
|
||||
if (HasSubContent)
|
||||
{
|
||||
if (m_subExpandBtn.gameObject.activeSelf != subContentWanted)
|
||||
m_subExpandBtn.gameObject.SetActive(subContentWanted);
|
||||
|
||||
if (!subContentWanted && m_subContentParent.activeSelf)
|
||||
ToggleSubcontent();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ConstructSubcontent()
|
||||
{
|
||||
m_subContentConstructed = true;
|
||||
}
|
||||
|
||||
public void ToggleSubcontent()
|
||||
{
|
||||
if (!this.m_subContentParent.activeSelf)
|
||||
{
|
||||
this.m_subContentParent.SetActive(true);
|
||||
this.m_subContentParent.transform.SetAsLastSibling();
|
||||
m_subExpandBtn.GetComponentInChildren<Text>().text = "▼";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_subContentParent.SetActive(false);
|
||||
m_subExpandBtn.GetComponentInChildren<Text>().text = "▲";
|
||||
}
|
||||
|
||||
OnToggleSubcontent(m_subContentParent.activeSelf);
|
||||
|
||||
RefreshElementsAfterUpdate();
|
||||
}
|
||||
|
||||
internal virtual void OnToggleSubcontent(bool toggle)
|
||||
{
|
||||
if (!m_subContentConstructed)
|
||||
ConstructSubcontent();
|
||||
}
|
||||
|
||||
internal MethodInfo m_toStringMethod;
|
||||
internal MethodInfo m_toStringFormatMethod;
|
||||
internal bool m_gotToStringMethods;
|
||||
|
||||
public string GetDefaultLabel(bool updateType = true)
|
||||
{
|
||||
var valueType = Value?.GetType() ?? this.FallbackType;
|
||||
if (updateType)
|
||||
m_richValueType = SignatureHighlighter.ParseFullSyntax(valueType, true);
|
||||
|
||||
if (!Owner.HasEvaluated)
|
||||
return m_defaultLabel = $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
|
||||
|
||||
if (Value.IsNullOrDestroyed())
|
||||
return m_defaultLabel = $"<color=grey>null</color> ({m_richValueType})";
|
||||
|
||||
string label;
|
||||
|
||||
// Two dirty fixes for TextAsset and EventSystem, which can have very long ToString results.
|
||||
if (Value is TextAsset textAsset)
|
||||
{
|
||||
label = textAsset.text;
|
||||
|
||||
if (label.Length > 10)
|
||||
label = $"{label.Substring(0, 10)}...";
|
||||
|
||||
label = $"\"{label}\" {textAsset.name} ({m_richValueType})";
|
||||
}
|
||||
else if (Value is EventSystem)
|
||||
{
|
||||
label = m_richValueType;
|
||||
}
|
||||
else // For everything else...
|
||||
{
|
||||
if (!m_gotToStringMethods)
|
||||
{
|
||||
m_gotToStringMethods = true;
|
||||
|
||||
m_toStringMethod = valueType.GetMethod("ToString", new Type[0]);
|
||||
m_toStringFormatMethod = valueType.GetMethod("ToString", new Type[] { typeof(string) });
|
||||
|
||||
// test format method actually works
|
||||
try
|
||||
{
|
||||
m_toStringFormatMethod.Invoke(Value, new object[] { "F3" });
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_toStringFormatMethod = null;
|
||||
}
|
||||
}
|
||||
|
||||
string toString;
|
||||
if (m_toStringFormatMethod != null)
|
||||
toString = (string)m_toStringFormatMethod.Invoke(Value, new object[] { "F3" });
|
||||
else
|
||||
toString = (string)m_toStringMethod.Invoke(Value, new object[0]);
|
||||
|
||||
toString = toString ?? "";
|
||||
|
||||
string typeName = valueType.FullName;
|
||||
if (typeName.StartsWith("Il2CppSystem."))
|
||||
typeName = typeName.Substring(6, typeName.Length - 6);
|
||||
|
||||
toString = ReflectionProvider.Instance.ProcessTypeNameInString(valueType, toString, ref typeName);
|
||||
|
||||
// If the ToString is just the type name, use our syntax highlighted type name instead.
|
||||
if (toString == typeName)
|
||||
{
|
||||
label = m_richValueType;
|
||||
}
|
||||
else // Otherwise, parse the result and put our highlighted name in.
|
||||
{
|
||||
if (toString.Length > 200)
|
||||
toString = toString.Substring(0, 200) + "...";
|
||||
|
||||
label = toString;
|
||||
|
||||
var unityType = $"({valueType.FullName})";
|
||||
if (Value is UnityEngine.Object && label.Contains(unityType))
|
||||
label = label.Replace(unityType, $"({m_richValueType})");
|
||||
else
|
||||
label += $" ({m_richValueType})";
|
||||
}
|
||||
}
|
||||
|
||||
return m_defaultLabel = label;
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_mainContentParent;
|
||||
internal GameObject m_subContentParent;
|
||||
|
||||
internal GameObject m_valueContent;
|
||||
internal GameObject m_inspectButton;
|
||||
internal Text m_baseLabel;
|
||||
|
||||
internal Button m_subExpandBtn;
|
||||
internal bool m_subContentConstructed;
|
||||
|
||||
public virtual void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
m_UIConstructed = true;
|
||||
|
||||
m_valueContent = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||
m_valueContent.name = "InteractiveValue.ValueContent";
|
||||
var mainRect = m_valueContent.GetComponent<RectTransform>();
|
||||
mainRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);
|
||||
var mainGroup = m_valueContent.GetComponent<HorizontalLayoutGroup>();
|
||||
mainGroup.childForceExpandWidth = false;
|
||||
mainGroup.SetChildControlWidth(true);
|
||||
mainGroup.childForceExpandHeight = false;
|
||||
mainGroup.SetChildControlHeight(true);
|
||||
mainGroup.spacing = 4;
|
||||
mainGroup.childAlignment = TextAnchor.UpperLeft;
|
||||
var mainLayout = m_valueContent.AddComponent<LayoutElement>();
|
||||
mainLayout.flexibleWidth = 9000;
|
||||
mainLayout.minWidth = 175;
|
||||
mainLayout.minHeight = 25;
|
||||
mainLayout.flexibleHeight = 0;
|
||||
|
||||
// subcontent expand button TODO
|
||||
if (HasSubContent)
|
||||
{
|
||||
var subBtnObj = UIFactory.CreateButton(m_valueContent, new Color(0.3f, 0.3f, 0.3f));
|
||||
var btnLayout = subBtnObj.AddComponent<LayoutElement>();
|
||||
btnLayout.minHeight = 25;
|
||||
btnLayout.minWidth = 25;
|
||||
btnLayout.flexibleWidth = 0;
|
||||
btnLayout.flexibleHeight = 0;
|
||||
var btnText = subBtnObj.GetComponentInChildren<Text>();
|
||||
btnText.text = "▲";
|
||||
m_subExpandBtn = subBtnObj.GetComponent<Button>();
|
||||
m_subExpandBtn.onClick.AddListener(() =>
|
||||
{
|
||||
ToggleSubcontent();
|
||||
});
|
||||
}
|
||||
|
||||
// inspect button
|
||||
|
||||
m_inspectButton = UIFactory.CreateButton(m_valueContent, new Color(0.3f, 0.3f, 0.3f, 0.2f));
|
||||
var inspectLayout = m_inspectButton.AddComponent<LayoutElement>();
|
||||
inspectLayout.minWidth = 60;
|
||||
inspectLayout.minHeight = 25;
|
||||
inspectLayout.flexibleHeight = 0;
|
||||
inspectLayout.flexibleWidth = 0;
|
||||
var inspectText = m_inspectButton.GetComponentInChildren<Text>();
|
||||
inspectText.text = "Inspect";
|
||||
var inspectBtn = m_inspectButton.GetComponent<Button>();
|
||||
|
||||
inspectBtn.onClick.AddListener(OnInspectClicked);
|
||||
void OnInspectClicked()
|
||||
{
|
||||
if (!Value.IsNullOrDestroyed(false))
|
||||
InspectorManager.Instance.Inspect(this.Value, this.Owner);
|
||||
}
|
||||
|
||||
m_inspectButton.SetActive(false);
|
||||
|
||||
// value label
|
||||
|
||||
var labelObj = UIFactory.CreateLabel(m_valueContent, TextAnchor.MiddleLeft);
|
||||
m_baseLabel = labelObj.GetComponent<Text>();
|
||||
var labelLayout = labelObj.AddComponent<LayoutElement>();
|
||||
labelLayout.flexibleWidth = 9000;
|
||||
labelLayout.minHeight = 25;
|
||||
|
||||
m_subContentParent = subGroup;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
360
src/Core/Inspectors/Reflection/ReflectionInspector.cs
Normal file
360
src/Core/Inspectors/Reflection/ReflectionInspector.cs
Normal file
@ -0,0 +1,360 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core.Inspectors.Reflection;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class ReflectionInspector : InspectorBase
|
||||
{
|
||||
#region STATIC
|
||||
|
||||
public static ReflectionInspector ActiveInstance { get; private set; }
|
||||
|
||||
static ReflectionInspector()
|
||||
{
|
||||
PanelDragger.OnFinishResize += OnContainerResized;
|
||||
SceneExplorer.OnToggleShow += OnContainerResized;
|
||||
}
|
||||
|
||||
private static void OnContainerResized()
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.ReflectionUI.m_widthUpdateWanted = true;
|
||||
}
|
||||
|
||||
// Blacklists
|
||||
private static readonly HashSet<string> bl_typeAndMember = new HashSet<string>
|
||||
{
|
||||
#if CPP
|
||||
// these cause a crash in IL2CPP
|
||||
"Type.DeclaringMethod",
|
||||
"Rigidbody2D.Cast",
|
||||
"Collider2D.Cast",
|
||||
"Collider2D.Raycast",
|
||||
"Texture2D.SetPixelDataImpl",
|
||||
"Camera.CalculateProjectionMatrixFromPhysicalProperties",
|
||||
#endif
|
||||
};
|
||||
private static readonly HashSet<string> bl_memberNameStartsWith = new HashSet<string>
|
||||
{
|
||||
// these are redundant
|
||||
"get_",
|
||||
"set_",
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region INSTANCE
|
||||
|
||||
public override string TabLabel => m_targetTypeShortName;
|
||||
|
||||
internal CacheObjectBase ParentMember { get; set; }
|
||||
|
||||
internal ReflectionInspectorUI ReflectionUI;
|
||||
|
||||
internal readonly Type m_targetType;
|
||||
internal readonly string m_targetTypeShortName;
|
||||
|
||||
// all cached members of the target
|
||||
internal CacheMember[] m_allMembers;
|
||||
// filtered members based on current filters
|
||||
internal readonly List<CacheMember> m_membersFiltered = new List<CacheMember>();
|
||||
// actual shortlist of displayed members
|
||||
internal readonly CacheMember[] m_displayedMembers = new CacheMember[ExplorerConfig.Instance.Default_Page_Limit];
|
||||
|
||||
internal bool m_autoUpdate;
|
||||
|
||||
public ReflectionInspector(object target) : base(target)
|
||||
{
|
||||
if (this is StaticInspector)
|
||||
m_targetType = target as Type;
|
||||
else
|
||||
m_targetType = ReflectionUtility.GetType(target);
|
||||
|
||||
m_targetTypeShortName = SignatureHighlighter.ParseFullSyntax(m_targetType, false);
|
||||
|
||||
ReflectionUI.ConstructUI();
|
||||
|
||||
CacheMembers(m_targetType);
|
||||
|
||||
FilterMembers();
|
||||
}
|
||||
|
||||
public override void CreateUIModule()
|
||||
{
|
||||
BaseUI = ReflectionUI = new ReflectionInspectorUI(this);
|
||||
}
|
||||
|
||||
public override void SetActive()
|
||||
{
|
||||
base.SetActive();
|
||||
ActiveInstance = this;
|
||||
}
|
||||
|
||||
public override void SetInactive()
|
||||
{
|
||||
base.SetInactive();
|
||||
ActiveInstance = null;
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
|
||||
if (this.BaseUI.Content)
|
||||
GameObject.Destroy(this.BaseUI.Content);
|
||||
}
|
||||
|
||||
internal void OnPageTurned()
|
||||
{
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
internal bool IsBlacklisted(string sig) => bl_typeAndMember.Any(it => sig.Contains(it));
|
||||
internal bool IsBlacklisted(MethodInfo method) => bl_memberNameStartsWith.Any(it => method.Name.StartsWith(it));
|
||||
|
||||
internal string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
|
||||
internal string AppendArgsToSig(ParameterInfo[] args)
|
||||
{
|
||||
string ret = " (";
|
||||
foreach (var param in args)
|
||||
ret += $"{param.ParameterType.Name} {param.Name}, ";
|
||||
ret += ")";
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void CacheMembers(Type type)
|
||||
{
|
||||
var list = new List<CacheMember>();
|
||||
var cachedSigs = new HashSet<string>();
|
||||
|
||||
var types = ReflectionUtility.GetAllBaseTypes(type);
|
||||
|
||||
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
||||
if (this is InstanceInspector)
|
||||
flags |= BindingFlags.Instance;
|
||||
|
||||
foreach (var declaringType in types)
|
||||
{
|
||||
var target = Target;
|
||||
target = target.Cast(declaringType);
|
||||
|
||||
IEnumerable<MemberInfo> infos = declaringType.GetMethods(flags);
|
||||
infos = infos.Concat(declaringType.GetProperties(flags));
|
||||
infos = infos.Concat(declaringType.GetFields(flags));
|
||||
|
||||
foreach (var member in infos)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sig = GetSig(member);
|
||||
|
||||
//ExplorerCore.Log($"Trying to cache member {sig}...");
|
||||
//ExplorerCore.Log(member.DeclaringType.FullName + "." + member.Name);
|
||||
|
||||
var mi = member as MethodInfo;
|
||||
var pi = member as PropertyInfo;
|
||||
var fi = member as FieldInfo;
|
||||
|
||||
if (IsBlacklisted(sig) || (mi != null && IsBlacklisted(mi)))
|
||||
continue;
|
||||
|
||||
var args = mi?.GetParameters() ?? pi?.GetIndexParameters();
|
||||
if (args != null)
|
||||
{
|
||||
if (!CacheMember.CanProcessArgs(args))
|
||||
continue;
|
||||
|
||||
sig += AppendArgsToSig(args);
|
||||
}
|
||||
|
||||
if (cachedSigs.Contains(sig))
|
||||
continue;
|
||||
|
||||
cachedSigs.Add(sig);
|
||||
|
||||
if (mi != null)
|
||||
list.Add(new CacheMethod(mi, target, ReflectionUI.m_scrollContent));
|
||||
else if (pi != null)
|
||||
list.Add(new CacheProperty(pi, target, ReflectionUI.m_scrollContent));
|
||||
else
|
||||
list.Add(new CacheField(fi, target, ReflectionUI.m_scrollContent));
|
||||
|
||||
list.Last().ParentInspector = this;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
|
||||
ExplorerCore.Log(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var typeList = types.ToList();
|
||||
|
||||
var sorted = new List<CacheMember>();
|
||||
sorted.AddRange(list.Where(it => it is CacheMethod)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(list.Where(it => it is CacheProperty)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(list.Where(it => it is CacheField)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
|
||||
m_allMembers = sorted.ToArray();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (m_autoUpdate)
|
||||
{
|
||||
foreach (var member in m_displayedMembers)
|
||||
{
|
||||
if (member == null) break;
|
||||
member.UpdateValue();
|
||||
}
|
||||
}
|
||||
|
||||
if (ReflectionUI.m_widthUpdateWanted)
|
||||
{
|
||||
if (!ReflectionUI.m_widthUpdateWaiting)
|
||||
ReflectionUI.m_widthUpdateWaiting = true;
|
||||
else
|
||||
{
|
||||
UpdateWidths();
|
||||
ReflectionUI.m_widthUpdateWaiting = false;
|
||||
ReflectionUI.m_widthUpdateWanted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnMemberFilterClicked(MemberTypes type, Button button)
|
||||
{
|
||||
if (ReflectionUI.m_lastActiveMemButton)
|
||||
{
|
||||
var lastColors = ReflectionUI.m_lastActiveMemButton.colors;
|
||||
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
ReflectionUI.m_lastActiveMemButton.colors = lastColors;
|
||||
}
|
||||
|
||||
ReflectionUI.m_memberFilter = type;
|
||||
ReflectionUI.m_lastActiveMemButton = button;
|
||||
|
||||
var colors = ReflectionUI.m_lastActiveMemButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
ReflectionUI.m_lastActiveMemButton.colors = colors;
|
||||
|
||||
FilterMembers(null, true);
|
||||
ReflectionUI.m_sliderScroller.m_slider.value = 1f;
|
||||
}
|
||||
|
||||
public void FilterMembers(string nameFilter = null, bool force = false)
|
||||
{
|
||||
int lastCount = m_membersFiltered.Count;
|
||||
m_membersFiltered.Clear();
|
||||
|
||||
nameFilter = nameFilter?.ToLower() ?? ReflectionUI.m_nameFilterText.text.ToLower();
|
||||
|
||||
foreach (var mem in m_allMembers)
|
||||
{
|
||||
// membertype filter
|
||||
if (ReflectionUI.m_memberFilter != MemberTypes.All && mem.MemInfo.MemberType != ReflectionUI.m_memberFilter)
|
||||
continue;
|
||||
|
||||
if (this is InstanceInspector ii && ii.m_scopeFilter != MemberScopes.All)
|
||||
{
|
||||
if (mem.IsStatic && ii.m_scopeFilter != MemberScopes.Static)
|
||||
continue;
|
||||
else if (!mem.IsStatic && ii.m_scopeFilter != MemberScopes.Instance)
|
||||
continue;
|
||||
}
|
||||
|
||||
// name filter
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !mem.NameForFiltering.Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
m_membersFiltered.Add(mem);
|
||||
}
|
||||
|
||||
if (force || lastCount != m_membersFiltered.Count)
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public void RefreshDisplay()
|
||||
{
|
||||
var members = m_membersFiltered;
|
||||
ReflectionUI.m_pageHandler.ListCount = members.Count;
|
||||
|
||||
// disable current members
|
||||
for (int i = 0; i < m_displayedMembers.Length; i++)
|
||||
{
|
||||
var mem = m_displayedMembers[i];
|
||||
if (mem != null)
|
||||
mem.Disable();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (members.Count < 1)
|
||||
return;
|
||||
|
||||
foreach (var itemIndex in ReflectionUI.m_pageHandler)
|
||||
{
|
||||
if (itemIndex >= members.Count)
|
||||
break;
|
||||
|
||||
CacheMember member = members[itemIndex];
|
||||
m_displayedMembers[itemIndex - ReflectionUI.m_pageHandler.StartIndex] = member;
|
||||
member.Enable();
|
||||
}
|
||||
|
||||
ReflectionUI.m_widthUpdateWanted = true;
|
||||
}
|
||||
|
||||
internal void UpdateWidths()
|
||||
{
|
||||
float labelWidth = 125;
|
||||
|
||||
foreach (var cache in m_displayedMembers)
|
||||
{
|
||||
if (cache == null)
|
||||
break;
|
||||
|
||||
var width = cache.GetMemberLabelWidth(ReflectionUI.m_scrollContentRect);
|
||||
|
||||
if (width > labelWidth)
|
||||
labelWidth = width;
|
||||
}
|
||||
|
||||
float valueWidth = ReflectionUI.m_scrollContentRect.rect.width - labelWidth - 20;
|
||||
|
||||
foreach (var cache in m_displayedMembers)
|
||||
{
|
||||
if (cache == null)
|
||||
break;
|
||||
cache.SetWidths(labelWidth, valueWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion // end instance
|
||||
}
|
||||
}
|
11
src/Core/Inspectors/Reflection/StaticInspector.cs
Normal file
11
src/Core/Inspectors/Reflection/StaticInspector.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class StaticInspector : ReflectionInspector
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[S]</color> {base.TabLabel}";
|
||||
|
||||
public StaticInspector(Type type) : base(type) { }
|
||||
}
|
||||
}
|
186
src/Core/ReflectionUtility.cs
Normal file
186
src/Core/ReflectionUtility.cs
Normal file
@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Core
|
||||
{
|
||||
public static class ReflectionUtility
|
||||
{
|
||||
public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
|
||||
|
||||
/// <summary>
|
||||
/// Helper for IL2CPP to get the underlying true Type (Unhollowed) of the object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to get the true Type for.</param>
|
||||
/// <returns>The most accurate Type of the object which could be identified.</returns>
|
||||
public static Type GetType(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
return ReflectionProvider.Instance.GetActualType(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cast an object to its underlying Type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to cast</param>
|
||||
/// <returns>The object, cast to the underlying Type if possible, otherwise the original object.</returns>
|
||||
public static object Cast(this object obj)
|
||||
=> Cast(obj, GetType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Cast an object to a Type, if possible.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to cast</param>
|
||||
/// <param name="castTo">The Type to cast to </param>
|
||||
/// <returns>The object, cast to the Type provided if possible, otherwise the original object.</returns>
|
||||
public static object Cast(this object obj, Type castTo)
|
||||
=> ReflectionProvider.Instance.Cast(obj, castTo);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided Type is assignable to IEnumerable.
|
||||
/// </summary>
|
||||
/// <param name="t">The Type to check</param>
|
||||
/// <returns>True if the Type is assignable to IEnumerable, otherwise false.</returns>
|
||||
public static bool IsEnumerable(this Type t)
|
||||
=> ReflectionProvider.Instance.IsAssignableFrom(typeof(IEnumerable), t);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided Type is assignable to IDictionary.
|
||||
/// </summary>
|
||||
/// <param name="t">The Type to check</param>
|
||||
/// <returns>True if the Type is assignable to IDictionary, otherwise false.</returns>
|
||||
public static bool IsDictionary(this Type t)
|
||||
=> ReflectionProvider.Instance.IsAssignableFrom(typeof(IDictionary), t);
|
||||
|
||||
public static bool LoadModule(string module)
|
||||
=> ReflectionProvider.Instance.LoadModule(module);
|
||||
|
||||
// cache for GetTypeByName
|
||||
internal static readonly Dictionary<string, Type> s_typesByName = new Dictionary<string, Type>();
|
||||
|
||||
/// <summary>
|
||||
/// Find a <see cref="Type"/> in the current AppDomain whose <see cref="Type.FullName"/> matches the provided <paramref name="fullName"/>.
|
||||
/// </summary>
|
||||
/// <param name="fullName">The <see cref="Type.FullName"/> you want to search for - case sensitive and full matches only.</param>
|
||||
/// <returns>The Type if found, otherwise null.</returns>
|
||||
public static Type GetTypeByName(string fullName)
|
||||
{
|
||||
s_typesByName.TryGetValue(fullName, out Type ret);
|
||||
|
||||
if (ret != null)
|
||||
return ret;
|
||||
|
||||
foreach (var type in from asm in AppDomain.CurrentDomain.GetAssemblies()
|
||||
from type in asm.TryGetTypes()
|
||||
select type)
|
||||
{
|
||||
if (type.FullName == fullName)
|
||||
{
|
||||
ret = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_typesByName.ContainsKey(fullName))
|
||||
s_typesByName[fullName] = ret;
|
||||
else
|
||||
s_typesByName.Add(fullName, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// cache for GetBaseTypes
|
||||
internal static readonly Dictionary<string, Type[]> s_cachedTypeInheritance = new Dictionary<string, Type[]>();
|
||||
|
||||
/// <summary>
|
||||
/// Get all base types of the provided Type, including itself.
|
||||
/// </summary>
|
||||
public static Type[] GetAllBaseTypes(this object obj) => GetAllBaseTypes(GetType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Get all base types of the provided Type, including itself.
|
||||
/// </summary>
|
||||
public static Type[] GetAllBaseTypes(this Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException("type");
|
||||
|
||||
var name = type.AssemblyQualifiedName;
|
||||
|
||||
if (s_cachedTypeInheritance.TryGetValue(name, out Type[] ret))
|
||||
return ret;
|
||||
|
||||
List<Type> list = new List<Type>();
|
||||
|
||||
while (type != null)
|
||||
{
|
||||
list.Add(type);
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
ret = list.ToArray();
|
||||
|
||||
s_cachedTypeInheritance.Add(name, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safely get all valid Types inside an Assembly.
|
||||
/// </summary>
|
||||
/// <param name="asm">The Assembly to find Types in.</param>
|
||||
/// <returns>All possible Types which could be retrieved from the Assembly, or an empty array.</returns>
|
||||
public static IEnumerable<Type> TryGetTypes(this Assembly asm)
|
||||
{
|
||||
try
|
||||
{
|
||||
return asm.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
return asm.GetExportedTypes();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return e.Types.Where(t => t != null);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Enumerable.Empty<Type>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper to display a simple "{ExceptionType}: {Message}" of the exception, and optionally use the inner-most exception.
|
||||
/// </summary>
|
||||
/// <param name="e">The Exception to convert to string.</param>
|
||||
/// <param name="innerMost">Should the inner-most Exception of the stack be used? If false, the Exception you provided will be used directly.</param>
|
||||
/// <returns>The exception to string.</returns>
|
||||
public static string ReflectionExToString(this Exception e, bool innerMost = false)
|
||||
{
|
||||
if (innerMost)
|
||||
{
|
||||
while (e.InnerException != null)
|
||||
{
|
||||
#if CPP
|
||||
if (e.InnerException is System.Runtime.CompilerServices.RuntimeWrappedException)
|
||||
break;
|
||||
#endif
|
||||
e = e.InnerException;
|
||||
}
|
||||
}
|
||||
|
||||
return $"{e.GetType()}: {e.Message}";
|
||||
}
|
||||
}
|
||||
}
|
76
src/Core/Runtime/Il2Cpp/AssetBundle.cs
Normal file
76
src/Core/Runtime/Il2Cpp/AssetBundle.cs
Normal file
@ -0,0 +1,76 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnhollowerBaseLib;
|
||||
using UnhollowerRuntimeLib;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core.Runtime.Il2Cpp;
|
||||
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public class AssetBundle
|
||||
{
|
||||
// ~~~~~~~~~~~~ Static ~~~~~~~~~~~~
|
||||
|
||||
internal delegate IntPtr d_LoadFromFile(IntPtr path, uint crc, ulong offset);
|
||||
|
||||
public static AssetBundle LoadFromFile(string path)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadFromFile>("UnityEngine.AssetBundle::LoadFromFile_Internal");
|
||||
|
||||
var ptr = iCall.Invoke(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0UL);
|
||||
|
||||
return new AssetBundle(ptr);
|
||||
}
|
||||
|
||||
private delegate IntPtr d_LoadFromMemory(IntPtr binary, uint crc);
|
||||
|
||||
public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadFromMemory>("UnityEngine.AssetBundle::LoadFromMemory_Internal");
|
||||
|
||||
var ptr = iCall(((Il2CppStructArray<byte>) binary).Pointer, crc);
|
||||
|
||||
return new AssetBundle(ptr);
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~ Instance ~~~~~~~~~~~~
|
||||
|
||||
private readonly IntPtr m_bundlePtr = IntPtr.Zero;
|
||||
|
||||
public AssetBundle(IntPtr ptr) { m_bundlePtr = ptr; }
|
||||
|
||||
// LoadAllAssets()
|
||||
|
||||
internal delegate IntPtr d_LoadAssetWithSubAssets_Internal(IntPtr _this, IntPtr name, IntPtr type);
|
||||
|
||||
public UnityEngine.Object[] LoadAllAssets()
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal");
|
||||
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), Il2CppType.Of<UnityEngine.Object>().Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return new UnityEngine.Object[0];
|
||||
|
||||
return new Il2CppReferenceArray<UnityEngine.Object>(ptr);
|
||||
}
|
||||
|
||||
// LoadAsset<T>(string name, Type type)
|
||||
|
||||
internal delegate IntPtr d_LoadAsset_Internal(IntPtr _this, IntPtr name, IntPtr type);
|
||||
|
||||
public T LoadAsset<T>(string name) where T : UnityEngine.Object
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal");
|
||||
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), Il2CppType.Of<T>().Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new UnityEngine.Object(ptr).TryCast<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
43
src/Core/Runtime/Il2Cpp/ICallManager.cs
Normal file
43
src/Core/Runtime/Il2Cpp/ICallManager.cs
Normal file
@ -0,0 +1,43 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
||||
public static class ICallManager
|
||||
{
|
||||
private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();
|
||||
|
||||
/// <summary>
|
||||
/// Helper to get and cache an iCall by providing the signature (eg. "UnityEngine.Resources::FindObjectsOfTypeAll").
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Type of Delegate to provide for the iCall.</typeparam>
|
||||
/// <param name="signature">The signature of the iCall you want to get.</param>
|
||||
/// <returns>The <typeparamref name="T"/> delegate if successful.</returns>
|
||||
/// <exception cref="MissingMethodException">If the iCall could not be found.</exception>
|
||||
public static T GetICall<T>(string signature) where T : Delegate
|
||||
{
|
||||
if (iCallCache.ContainsKey(signature))
|
||||
return (T)iCallCache[signature];
|
||||
|
||||
IntPtr ptr = il2cpp_resolve_icall(signature);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new MissingMethodException($"Could not resolve internal call by name '{signature}'!");
|
||||
}
|
||||
|
||||
Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T));
|
||||
iCallCache.Add(signature, iCall);
|
||||
|
||||
return (T)iCall;
|
||||
}
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr il2cpp_resolve_icall([MarshalAs(UnmanagedType.LPStr)] string name);
|
||||
}
|
||||
}
|
||||
#endif
|
156
src/Core/Runtime/Il2Cpp/Il2CppCoroutine.cs
Normal file
156
src/Core/Runtime/Il2Cpp/Il2CppCoroutine.cs
Normal file
@ -0,0 +1,156 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityEngine;
|
||||
|
||||
// CREDIT HerpDerpenstine
|
||||
// https://github.com/LavaGang/MelonLoader/blob/master/MelonLoader.Support.Il2Cpp/MelonCoroutines.cs
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
public static class Il2CppCoroutine
|
||||
{
|
||||
private struct CoroTuple
|
||||
{
|
||||
public object WaitCondition;
|
||||
public IEnumerator Coroutine;
|
||||
}
|
||||
private static readonly List<CoroTuple> ourCoroutinesStore = new List<CoroTuple>();
|
||||
private static readonly List<IEnumerator> ourNextFrameCoroutines = new List<IEnumerator>();
|
||||
private static readonly List<IEnumerator> ourWaitForFixedUpdateCoroutines = new List<IEnumerator>();
|
||||
private static readonly List<IEnumerator> ourWaitForEndOfFrameCoroutines = new List<IEnumerator>();
|
||||
|
||||
private static readonly List<IEnumerator> tempList = new List<IEnumerator>();
|
||||
|
||||
internal static object Start(IEnumerator routine)
|
||||
{
|
||||
if (routine != null) ProcessNextOfCoroutine(routine);
|
||||
return routine;
|
||||
}
|
||||
|
||||
internal static void Stop(IEnumerator enumerator)
|
||||
{
|
||||
if (ourNextFrameCoroutines.Contains(enumerator)) // the coroutine is running itself
|
||||
ourNextFrameCoroutines.Remove(enumerator);
|
||||
else
|
||||
{
|
||||
int coroTupleIndex = ourCoroutinesStore.FindIndex(c => c.Coroutine == enumerator);
|
||||
if (coroTupleIndex != -1) // the coroutine is waiting for a subroutine
|
||||
{
|
||||
object waitCondition = ourCoroutinesStore[coroTupleIndex].WaitCondition;
|
||||
if (waitCondition is IEnumerator waitEnumerator)
|
||||
Stop(waitEnumerator);
|
||||
|
||||
ourCoroutinesStore.RemoveAt(coroTupleIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessCoroList(List<IEnumerator> target)
|
||||
{
|
||||
if (target.Count == 0) return;
|
||||
|
||||
// use a temp list to make sure waits made during processing are not handled by same processing invocation
|
||||
// additionally, a temp list reduces allocations compared to an array
|
||||
tempList.AddRange(target);
|
||||
target.Clear();
|
||||
foreach (var enumerator in tempList) ProcessNextOfCoroutine(enumerator);
|
||||
tempList.Clear();
|
||||
}
|
||||
|
||||
internal static void Process()
|
||||
{
|
||||
for (var i = ourCoroutinesStore.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var tuple = ourCoroutinesStore[i];
|
||||
if (tuple.WaitCondition is WaitForSeconds waitForSeconds)
|
||||
{
|
||||
if ((waitForSeconds.m_Seconds -= Time.deltaTime) <= 0)
|
||||
{
|
||||
ourCoroutinesStore.RemoveAt(i);
|
||||
ProcessNextOfCoroutine(tuple.Coroutine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProcessCoroList(ourNextFrameCoroutines);
|
||||
}
|
||||
|
||||
internal static void ProcessWaitForFixedUpdate() => ProcessCoroList(ourWaitForFixedUpdateCoroutines);
|
||||
|
||||
internal static void ProcessWaitForEndOfFrame() => ProcessCoroList(ourWaitForEndOfFrameCoroutines);
|
||||
|
||||
private static void ProcessNextOfCoroutine(IEnumerator enumerator)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!enumerator.MoveNext()) // Run the next step of the coroutine. If it's done, restore the parent routine
|
||||
{
|
||||
var indices = ourCoroutinesStore.Select((it, idx) => (idx, it)).Where(it => it.it.WaitCondition == enumerator).Select(it => it.idx).ToList();
|
||||
for (var i = indices.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var index = indices[i];
|
||||
ourNextFrameCoroutines.Add(ourCoroutinesStore[index].Coroutine);
|
||||
ourCoroutinesStore.RemoveAt(index);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogError(e.ToString());
|
||||
Stop(FindOriginalCoro(enumerator)); // We want the entire coroutine hierachy to stop when an error happen
|
||||
}
|
||||
|
||||
var next = enumerator.Current;
|
||||
switch (next)
|
||||
{
|
||||
case null:
|
||||
ourNextFrameCoroutines.Add(enumerator);
|
||||
return;
|
||||
case WaitForFixedUpdate _:
|
||||
ourWaitForFixedUpdateCoroutines.Add(enumerator);
|
||||
return;
|
||||
case WaitForEndOfFrame _:
|
||||
ourWaitForEndOfFrameCoroutines.Add(enumerator);
|
||||
return;
|
||||
case WaitForSeconds _:
|
||||
break; // do nothing, this one is supported in Process
|
||||
case Il2CppObjectBase il2CppObjectBase:
|
||||
var nextAsEnumerator = il2CppObjectBase.TryCast<Il2CppSystem.Collections.IEnumerator>();
|
||||
if (nextAsEnumerator != null) // il2cpp IEnumerator also handles CustomYieldInstruction
|
||||
next = new Il2CppEnumeratorWrapper(nextAsEnumerator);
|
||||
else
|
||||
ExplorerCore.LogWarning($"Unknown coroutine yield object of type {il2CppObjectBase} for coroutine {enumerator}");
|
||||
break;
|
||||
}
|
||||
|
||||
ourCoroutinesStore.Add(new CoroTuple { WaitCondition = next, Coroutine = enumerator });
|
||||
|
||||
if (next is IEnumerator nextCoro)
|
||||
ProcessNextOfCoroutine(nextCoro);
|
||||
}
|
||||
|
||||
private static IEnumerator FindOriginalCoro(IEnumerator enumerator)
|
||||
{
|
||||
int index = ourCoroutinesStore.FindIndex(ct => ct.WaitCondition == enumerator);
|
||||
if (index == -1)
|
||||
return enumerator;
|
||||
return FindOriginalCoro(ourCoroutinesStore[index].Coroutine);
|
||||
}
|
||||
|
||||
private class Il2CppEnumeratorWrapper : IEnumerator
|
||||
{
|
||||
private readonly Il2CppSystem.Collections.IEnumerator il2cppEnumerator;
|
||||
|
||||
public Il2CppEnumeratorWrapper(Il2CppSystem.Collections.IEnumerator il2CppEnumerator) => il2cppEnumerator = il2CppEnumerator;
|
||||
public bool MoveNext() => il2cppEnumerator.MoveNext();
|
||||
public void Reset() => il2cppEnumerator.Reset();
|
||||
public object Current => il2cppEnumerator.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
127
src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
Normal file
127
src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
Normal file
@ -0,0 +1,127 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
using System.Text;
|
||||
using UnhollowerBaseLib;
|
||||
using UnhollowerRuntimeLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
public class Il2CppProvider : RuntimeProvider
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
Reflection = new Il2CppReflection();
|
||||
TextureUtil = new Il2CppTextureUtil();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Application.add_logMessageReceived(new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog));
|
||||
|
||||
var logType = ReflectionUtility.GetTypeByName("UnityEngine.Application+LogCallback");
|
||||
var castMethod = logType.GetMethod("op_Implicit", new[] { typeof(Action<string, string, LogType>) });
|
||||
var addMethod = typeof(Application).GetMethod("add_logMessageReceived", BF.Static | BF.Public, null, new[] { logType }, null);
|
||||
addMethod.Invoke(null, new[]
|
||||
{
|
||||
castMethod.Invoke(null, new[] { new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog) })
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
ExplorerCore.LogWarning("Exception setting up Unity log listener, make sure Unity libraries have been unstripped!");
|
||||
}
|
||||
}
|
||||
|
||||
public override void StartConsoleCoroutine(IEnumerator routine)
|
||||
{
|
||||
Il2CppCoroutine.Start(routine);
|
||||
}
|
||||
|
||||
internal delegate IntPtr d_LayerToName(int layer);
|
||||
|
||||
public override string LayerToName(int layer)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LayerToName>("UnityEngine.LayerMask::LayerToName");
|
||||
return IL2CPP.Il2CppStringToManaged(iCall.Invoke(layer));
|
||||
}
|
||||
|
||||
internal delegate IntPtr d_FindObjectsOfTypeAll(IntPtr type);
|
||||
|
||||
public override UnityEngine.Object[] FindObjectsOfTypeAll(Type type)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_FindObjectsOfTypeAll>("UnityEngine.Resources::FindObjectsOfTypeAll");
|
||||
var cppType = Il2CppType.From(type);
|
||||
|
||||
return new Il2CppReferenceArray<UnityEngine.Object>(iCall.Invoke(cppType.Pointer));
|
||||
}
|
||||
|
||||
public override int GetSceneHandle(Scene scene)
|
||||
=> scene.handle;
|
||||
|
||||
//Scene.GetRootGameObjects();
|
||||
|
||||
internal delegate void d_GetRootGameObjects(int handle, IntPtr list);
|
||||
|
||||
public override GameObject[] GetRootGameObjects(Scene scene) => GetRootGameObjects(scene.handle);
|
||||
|
||||
public static GameObject[] GetRootGameObjects(int handle)
|
||||
{
|
||||
if (handle == -1)
|
||||
return new GameObject[0];
|
||||
|
||||
int count = GetRootCount(handle);
|
||||
|
||||
if (count < 1)
|
||||
return new GameObject[0];
|
||||
|
||||
var list = new Il2CppSystem.Collections.Generic.List<GameObject>(count);
|
||||
|
||||
var iCall = ICallManager.GetICall<d_GetRootGameObjects>("UnityEngine.SceneManagement.Scene::GetRootGameObjectsInternal");
|
||||
|
||||
iCall.Invoke(handle, list.Pointer);
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
//Scene.rootCount;
|
||||
|
||||
internal delegate int d_GetRootCountInternal(int handle);
|
||||
|
||||
public override int GetRootCount(Scene scene) => GetRootCount(scene.handle);
|
||||
|
||||
public static int GetRootCount(int handle)
|
||||
{
|
||||
return ICallManager.GetICall<d_GetRootCountInternal>("UnityEngine.SceneManagement.Scene::GetRootCountInternal")
|
||||
.Invoke(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Il2CppExtensions
|
||||
{
|
||||
public static void AddListener(this UnityEvent action, Action listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void SetChildControlHeight(this HorizontalOrVerticalLayoutGroup group, bool value) => group.childControlHeight = value;
|
||||
public static void SetChildControlWidth(this HorizontalOrVerticalLayoutGroup group, bool value) => group.childControlWidth = value;
|
||||
}
|
||||
|
||||
#endif
|
362
src/Core/Runtime/Il2Cpp/Il2CppReflection.cs
Normal file
362
src/Core/Runtime/Il2Cpp/Il2CppReflection.cs
Normal file
@ -0,0 +1,362 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnhollowerRuntimeLib;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using UnityExplorer.Core;
|
||||
using CppType = Il2CppSystem.Type;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
||||
public class Il2CppReflection : ReflectionProvider
|
||||
{
|
||||
public Il2CppReflection() : base()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
TryLoadGameModules();
|
||||
}
|
||||
|
||||
public override object Cast(object obj, Type castTo)
|
||||
{
|
||||
return Il2CppCast(obj, castTo);
|
||||
}
|
||||
|
||||
public override string ProcessTypeNameInString(Type type, string theString, ref string typeName)
|
||||
{
|
||||
if (!Il2CppTypeNotNull(type))
|
||||
return theString;
|
||||
|
||||
var cppType = Il2CppType.From(type);
|
||||
if (cppType != null && s_deobfuscatedTypeNames.ContainsKey(cppType.FullName))
|
||||
{
|
||||
typeName = s_deobfuscatedTypeNames[cppType.FullName];
|
||||
theString = theString.Replace(cppType.FullName, typeName);
|
||||
}
|
||||
|
||||
return theString;
|
||||
}
|
||||
|
||||
public override Type GetActualType(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
var type = obj.GetType();
|
||||
|
||||
if (obj is Il2CppSystem.Object cppObject)
|
||||
{
|
||||
// weird specific case - if the object is an Il2CppSystem.Type, then return so manually.
|
||||
if (cppObject is CppType)
|
||||
return typeof(CppType);
|
||||
|
||||
if (!string.IsNullOrEmpty(type.Namespace))
|
||||
{
|
||||
// Il2CppSystem-namespace objects should just return GetType,
|
||||
// because using GetIl2CppType returns the System namespace type instead.
|
||||
if (type.Namespace.StartsWith("System.") || type.Namespace.StartsWith("Il2CppSystem."))
|
||||
return cppObject.GetType();
|
||||
}
|
||||
|
||||
var cppType = cppObject.GetIl2CppType();
|
||||
|
||||
// check if type is injected
|
||||
IntPtr classPtr = il2cpp_object_get_class(cppObject.Pointer);
|
||||
if (RuntimeSpecificsStore.IsInjected(classPtr))
|
||||
{
|
||||
var typeByName = ReflectionUtility.GetTypeByName(cppType.FullName);
|
||||
if (typeByName != null)
|
||||
return typeByName;
|
||||
}
|
||||
|
||||
// this should be fine for all other il2cpp objects
|
||||
var getType = GetMonoType(cppType);
|
||||
if (getType != null)
|
||||
return getType;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
// caching for GetMonoType
|
||||
private static readonly Dictionary<string, Type> Il2CppToMonoType = new Dictionary<string, Type>();
|
||||
|
||||
// keep deobfuscated type name cache, used to display proper name.
|
||||
internal static Dictionary<string, string> s_deobfuscatedTypeNames = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Try to get the Mono (Unhollowed) Type representation of the provided <see cref="Il2CppSystem.Type"/>.
|
||||
/// </summary>
|
||||
/// <param name="cppType">The Cpp Type you want to convert to Mono.</param>
|
||||
/// <returns>The Mono Type if found, otherwise null.</returns>
|
||||
public static Type GetMonoType(CppType cppType)
|
||||
{
|
||||
string name = cppType.AssemblyQualifiedName;
|
||||
|
||||
if (Il2CppToMonoType.ContainsKey(name))
|
||||
return Il2CppToMonoType[name];
|
||||
|
||||
Type ret = Type.GetType(name);
|
||||
|
||||
if (ret == null)
|
||||
{
|
||||
string baseName = cppType.FullName;
|
||||
string baseAssembly = cppType.Assembly.GetName().name;
|
||||
|
||||
ret = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.FirstOrDefault(a
|
||||
=> a.GetName().Name == baseAssembly)?
|
||||
.TryGetTypes()
|
||||
.FirstOrDefault(t
|
||||
=> t.CustomAttributes.Any(ca
|
||||
=> ca.AttributeType.Name == "ObfuscatedNameAttribute"
|
||||
&& (string)ca.ConstructorArguments[0].Value == baseName));
|
||||
|
||||
if (ret != null)
|
||||
{
|
||||
// deobfuscated type was found, add to cache.
|
||||
s_deobfuscatedTypeNames.Add(cppType.FullName, ret.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
Il2CppToMonoType.Add(name, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// cached class pointers for Il2CppCast
|
||||
private static readonly Dictionary<string, IntPtr> s_cppClassPointers = new Dictionary<string, IntPtr>();
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to cast the object to its underlying type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object you want to cast.</param>
|
||||
/// <returns>The object, as the underlying type if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(object obj) => Il2CppCast(obj, Instance.GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to cast the object to the provided type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object you want to cast.</param>
|
||||
/// <param name="castTo">The Type you want to cast to.</param>
|
||||
/// <returns>The object, as the type (or a normal C# object) if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(object obj, Type castTo)
|
||||
{
|
||||
if (!(obj is Il2CppSystem.Object ilObj))
|
||||
return obj;
|
||||
|
||||
if (!Il2CppTypeNotNull(castTo, out IntPtr castToPtr))
|
||||
return obj;
|
||||
|
||||
IntPtr castFromPtr = il2cpp_object_get_class(ilObj.Pointer);
|
||||
|
||||
if (!il2cpp_class_is_assignable_from(castToPtr, castFromPtr))
|
||||
return obj;
|
||||
|
||||
if (RuntimeSpecificsStore.IsInjected(castToPtr))
|
||||
return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(ilObj.Pointer);
|
||||
|
||||
return Activator.CreateInstance(castTo, ilObj.Pointer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Il2Cpp Class Pointer for the provided Mono (Unhollowed) Type.
|
||||
/// </summary>
|
||||
/// <param name="type">The Mono/Unhollowed Type you want the Il2Cpp Class Pointer for.</param>
|
||||
/// <returns>True if successful, false if not.</returns>
|
||||
public static bool Il2CppTypeNotNull(Type type) => Il2CppTypeNotNull(type, out _);
|
||||
|
||||
/// <summary>
|
||||
/// Get the Il2Cpp Class Pointer for the provided Mono (Unhollowed) Type.
|
||||
/// </summary>
|
||||
/// <param name="type">The Mono/Unhollowed Type you want the Il2Cpp Class Pointer for.</param>
|
||||
/// <param name="il2cppPtr">The IntPtr for the Il2Cpp class, or IntPtr.Zero if not found.</param>
|
||||
/// <returns>True if successful, false if not.</returns>
|
||||
public static bool Il2CppTypeNotNull(Type type, out IntPtr il2cppPtr)
|
||||
{
|
||||
if (s_cppClassPointers.TryGetValue(type.AssemblyQualifiedName, out il2cppPtr))
|
||||
return il2cppPtr != IntPtr.Zero;
|
||||
|
||||
il2cppPtr = (IntPtr)typeof(Il2CppClassPointerStore<>)
|
||||
.MakeGenericType(new Type[] { type })
|
||||
.GetField("NativeClassPtr", BF.Public | BF.Static)
|
||||
.GetValue(null);
|
||||
|
||||
s_cppClassPointers.Add(type.AssemblyQualifiedName, il2cppPtr);
|
||||
|
||||
return il2cppPtr != IntPtr.Zero;
|
||||
}
|
||||
|
||||
// Extern C++ methods
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern bool il2cpp_class_is_assignable_from(IntPtr klass, IntPtr oklass);
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr il2cpp_object_get_class(IntPtr obj);
|
||||
|
||||
internal static IntPtr s_cppEnumerableClassPtr;
|
||||
internal static IntPtr s_cppDictionaryClassPtr;
|
||||
|
||||
public override bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom)
|
||||
{
|
||||
if (toAssignTo.IsAssignableFrom(toAssignFrom))
|
||||
return true;
|
||||
|
||||
if (toAssignTo == typeof(IEnumerable))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (s_cppEnumerableClassPtr == IntPtr.Zero)
|
||||
Il2CppTypeNotNull(typeof(Il2CppSystem.Collections.IEnumerable), out s_cppEnumerableClassPtr);
|
||||
|
||||
if (s_cppEnumerableClassPtr != IntPtr.Zero
|
||||
&& Il2CppTypeNotNull(toAssignFrom, out IntPtr assignFromPtr)
|
||||
&& il2cpp_class_is_assignable_from(s_cppEnumerableClassPtr, assignFromPtr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else if (toAssignTo == typeof(IDictionary))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (s_cppDictionaryClassPtr == IntPtr.Zero)
|
||||
if (!Il2CppTypeNotNull(typeof(Il2CppSystem.Collections.IDictionary), out s_cppDictionaryClassPtr))
|
||||
return false;
|
||||
|
||||
if (Il2CppTypeNotNull(toAssignFrom, out IntPtr classPtr))
|
||||
{
|
||||
if (il2cpp_class_is_assignable_from(s_cppDictionaryClassPtr, classPtr))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsReflectionSupported(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gArgs = type.GetGenericArguments();
|
||||
if (!gArgs.Any())
|
||||
return true;
|
||||
|
||||
foreach (var gType in gArgs)
|
||||
{
|
||||
if (!Supported(gType))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
bool Supported(Type t)
|
||||
{
|
||||
if (!typeof(Il2CppSystem.Object).IsAssignableFrom(t))
|
||||
return true;
|
||||
|
||||
if (!Il2CppTypeNotNull(t, out IntPtr ptr))
|
||||
return false;
|
||||
|
||||
return CppType.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is CppType;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper for IL2CPP to try to make sure the Unhollowed game assemblies are actually loaded.
|
||||
|
||||
internal static void TryLoadGameModules()
|
||||
{
|
||||
Instance.LoadModule("Assembly-CSharp");
|
||||
Instance.LoadModule("Assembly-CSharp-firstpass");
|
||||
}
|
||||
|
||||
public override bool LoadModule(string module)
|
||||
{
|
||||
#if ML
|
||||
var path = Path.Combine("MelonLoader", "Managed", $"{module}.dll");
|
||||
#else
|
||||
var path = Path.Combine("BepInEx", "unhollowed", $"{module}.dll");
|
||||
#endif
|
||||
return LoadModuleInternal(path);
|
||||
}
|
||||
|
||||
internal static bool LoadModuleInternal(string fullPath)
|
||||
{
|
||||
if (!File.Exists(fullPath))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Assembly.Load(File.ReadAllBytes(fullPath));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.GetType() + ", " + e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~ not used ~~~~~~~~~~~~
|
||||
|
||||
// cached il2cpp unbox methods
|
||||
internal static readonly Dictionary<string, MethodInfo> s_unboxMethods = new Dictionary<string, MethodInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to unbox the object to the underlying struct type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object which is a struct underneath.</param>
|
||||
/// <returns>The struct if successful, otherwise null.</returns>
|
||||
public static object Unbox(object obj) => Unbox(obj, Instance.GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to unbox the object to the struct type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object which is a struct underneath.</param>
|
||||
/// <param name="type">The type of the struct you want to unbox to.</param>
|
||||
/// <returns>The struct if successful, otherwise null.</returns>
|
||||
public static object Unbox(object obj, Type type)
|
||||
{
|
||||
if (!type.IsValueType)
|
||||
return null;
|
||||
|
||||
if (!(obj is Il2CppSystem.Object))
|
||||
return obj;
|
||||
|
||||
var name = type.AssemblyQualifiedName;
|
||||
|
||||
if (!s_unboxMethods.ContainsKey(name))
|
||||
{
|
||||
s_unboxMethods.Add(name, typeof(Il2CppObjectBase)
|
||||
.GetMethod("Unbox")
|
||||
.MakeGenericMethod(type));
|
||||
}
|
||||
|
||||
return s_unboxMethods[name].Invoke(obj, new object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
77
src/Core/Runtime/Il2Cpp/Il2CppTextureUtil.cs
Normal file
77
src/Core/Runtime/Il2Cpp/Il2CppTextureUtil.cs
Normal file
@ -0,0 +1,77 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
public class Il2CppTextureUtil : TextureUtilProvider
|
||||
{
|
||||
public override Texture2D NewTexture2D(int width, int height)
|
||||
=> new Texture2D((int)width, (int)height, TextureFormat.RGBA32, Texture.GenerateAllMips, false, IntPtr.Zero);
|
||||
|
||||
internal delegate void d_Blit2(IntPtr source, IntPtr dest);
|
||||
|
||||
public override void Blit(Texture2D tex, RenderTexture rt)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_Blit2>("UnityEngine.Graphics::Blit2");
|
||||
iCall.Invoke(tex.Pointer, rt.Pointer);
|
||||
}
|
||||
|
||||
// byte[] ImageConversion.EncodeToPNG(this Texture2D image);
|
||||
|
||||
internal delegate IntPtr d_EncodeToPNG(IntPtr tex);
|
||||
|
||||
public override byte[] EncodeToPNG(Texture2D tex)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_EncodeToPNG>("UnityEngine.ImageConversion::EncodeToPNG");
|
||||
|
||||
IntPtr ptr = iCall.Invoke(tex.Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new Il2CppStructArray<byte>(ptr);
|
||||
}
|
||||
|
||||
// bool ImageConversion.LoadImage(this Texture2D tex, byte[] data, bool markNonReadable);
|
||||
|
||||
internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
|
||||
|
||||
public override bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
|
||||
{
|
||||
var il2cppArray = (Il2CppStructArray<byte>)data;
|
||||
|
||||
var iCall = ICallManager.GetICall<d_LoadImage>("UnityEngine.ImageConversion::LoadImage");
|
||||
|
||||
return iCall.Invoke(tex.Pointer, il2cppArray.Pointer, markNonReadable);
|
||||
}
|
||||
|
||||
// Sprite Sprite.Create
|
||||
|
||||
public override Sprite CreateSprite(Texture2D texture)
|
||||
{
|
||||
return CreateSpriteImpl(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 100f, 0u, Vector4.zero);
|
||||
}
|
||||
|
||||
internal delegate IntPtr d_CreateSprite(IntPtr texture, ref Rect rect, ref Vector2 pivot, float pixelsPerUnit,
|
||||
uint extrude, int meshType, ref Vector4 border, bool generateFallbackPhysicsShape);
|
||||
|
||||
public static Sprite CreateSpriteImpl(Texture texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, Vector4 border)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_CreateSprite>("UnityEngine.Sprite::CreateSprite_Injected");
|
||||
|
||||
var ptr = iCall.Invoke(texture.Pointer, ref rect, ref pivot, pixelsPerUnit, extrude, 1, ref border, false);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
return new Sprite(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
89
src/Core/Runtime/Mono/MonoProvider.cs
Normal file
89
src/Core/Runtime/Mono/MonoProvider.cs
Normal file
@ -0,0 +1,89 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.CSharp;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class MonoProvider : RuntimeProvider
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
Reflection = new MonoReflection();
|
||||
TextureUtil = new MonoTextureUtil();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
{
|
||||
Application.logMessageReceived += ExplorerCore.Instance.OnUnityLog;
|
||||
//SceneManager.sceneLoaded += ExplorerCore.Instance.OnSceneLoaded1;
|
||||
//SceneManager.activeSceneChanged += ExplorerCore.Instance.OnSceneLoaded2;
|
||||
}
|
||||
|
||||
public override void StartConsoleCoroutine(IEnumerator routine)
|
||||
{
|
||||
DummyBehaviour.Instance.StartCoroutine(routine);
|
||||
}
|
||||
|
||||
public override string LayerToName(int layer)
|
||||
=> LayerMask.LayerToName(layer);
|
||||
|
||||
public override UnityEngine.Object[] FindObjectsOfTypeAll(Type type)
|
||||
=> Resources.FindObjectsOfTypeAll(type);
|
||||
|
||||
private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionUtility.CommonFlags);
|
||||
|
||||
public override int GetSceneHandle(Scene scene)
|
||||
{
|
||||
return (int)fi_Scene_handle.GetValue(scene);
|
||||
}
|
||||
|
||||
public override GameObject[] GetRootGameObjects(Scene scene)
|
||||
{
|
||||
return scene.GetRootGameObjects();
|
||||
}
|
||||
|
||||
public override int GetRootCount(Scene scene)
|
||||
{
|
||||
return scene.rootCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MonoExtensions
|
||||
{
|
||||
public static void Clear(this StringBuilder sb)
|
||||
{
|
||||
sb.Remove(0, sb.Length);
|
||||
}
|
||||
|
||||
private static PropertyInfo pi_childControlHeight;
|
||||
|
||||
public static void SetChildControlHeight(this HorizontalOrVerticalLayoutGroup group, bool value)
|
||||
{
|
||||
if (pi_childControlHeight == null)
|
||||
pi_childControlHeight = group.GetType().GetProperty("childControlHeight");
|
||||
|
||||
pi_childControlHeight?.SetValue(group, value, null);
|
||||
}
|
||||
|
||||
private static PropertyInfo pi_childControlWidth;
|
||||
|
||||
public static void SetChildControlWidth(this HorizontalOrVerticalLayoutGroup group, bool value)
|
||||
{
|
||||
if (pi_childControlWidth == null)
|
||||
pi_childControlWidth = group.GetType().GetProperty("childControlWidth");
|
||||
|
||||
pi_childControlWidth?.SetValue(group, value, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
33
src/Core/Runtime/Mono/MonoReflection.cs
Normal file
33
src/Core/Runtime/Mono/MonoReflection.cs
Normal file
@ -0,0 +1,33 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class MonoReflection : ReflectionProvider
|
||||
{
|
||||
// Mono doesn't need to explicitly cast things.
|
||||
public override object Cast(object obj, Type castTo)
|
||||
=> obj;
|
||||
|
||||
// Vanilla GetType is fine for mono
|
||||
public override Type GetActualType(object obj)
|
||||
=> obj.GetType();
|
||||
|
||||
public override bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom)
|
||||
=> toAssignTo.IsAssignableFrom(toAssignFrom);
|
||||
|
||||
public override bool IsReflectionSupported(Type type)
|
||||
=> true;
|
||||
|
||||
public override bool LoadModule(string module)
|
||||
=> true;
|
||||
|
||||
public override string ProcessTypeNameInString(Type type, string theString, ref string typeName)
|
||||
=> theString;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
66
src/Core/Runtime/Mono/MonoTextureUtil.cs
Normal file
66
src/Core/Runtime/Mono/MonoTextureUtil.cs
Normal file
@ -0,0 +1,66 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class MonoTextureUtil : TextureUtilProvider
|
||||
{
|
||||
public override void Blit(Texture2D tex, RenderTexture rt)
|
||||
{
|
||||
Graphics.Blit(tex, rt);
|
||||
}
|
||||
|
||||
public override Sprite CreateSprite(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
||||
}
|
||||
|
||||
public override bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
|
||||
{
|
||||
return tex.LoadImage(data, markNonReadable);
|
||||
}
|
||||
|
||||
public override Texture2D NewTexture2D(int width, int height)
|
||||
{
|
||||
return new Texture2D(width, height);
|
||||
}
|
||||
|
||||
public override byte[] EncodeToPNG(Texture2D tex)
|
||||
{
|
||||
return EncodeToPNGSafe(tex);
|
||||
}
|
||||
|
||||
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod();
|
||||
private static MethodInfo m_encodeToPNGMethod;
|
||||
|
||||
public static byte[] EncodeToPNGSafe(Texture2D tex)
|
||||
{
|
||||
var method = EncodeToPNGMethod;
|
||||
|
||||
if (method.IsStatic)
|
||||
return (byte[])method.Invoke(null, new object[] { tex });
|
||||
else
|
||||
return (byte[])method.Invoke(tex, new object[0]);
|
||||
}
|
||||
|
||||
private static MethodInfo GetEncodeToPNGMethod()
|
||||
{
|
||||
if (ReflectionUtility.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion)
|
||||
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.CommonFlags);
|
||||
|
||||
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.CommonFlags);
|
||||
if (method != null)
|
||||
return m_encodeToPNGMethod = method;
|
||||
|
||||
ExplorerCore.Log("ERROR: Cannot get any EncodeToPNG method!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
29
src/Core/Runtime/ReflectionProvider.cs
Normal file
29
src/Core/Runtime/ReflectionProvider.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
{
|
||||
public abstract class ReflectionProvider
|
||||
{
|
||||
public static ReflectionProvider Instance;
|
||||
|
||||
public ReflectionProvider()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public abstract Type GetActualType(object obj);
|
||||
|
||||
public abstract object Cast(object obj, Type castTo);
|
||||
|
||||
public abstract bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom);
|
||||
|
||||
public abstract bool IsReflectionSupported(Type type);
|
||||
|
||||
public abstract string ProcessTypeNameInString(Type type, string theString, ref string typeName);
|
||||
|
||||
public abstract bool LoadModule(string module);
|
||||
}
|
||||
}
|
54
src/Core/Runtime/RuntimeProvider.cs
Normal file
54
src/Core/Runtime/RuntimeProvider.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
{
|
||||
// Work in progress, this will be used to replace all the "if CPP / if MONO"
|
||||
// pre-processor directives all over the codebase.
|
||||
|
||||
public abstract class RuntimeProvider
|
||||
{
|
||||
public static RuntimeProvider Instance;
|
||||
|
||||
public ReflectionProvider Reflection;
|
||||
public TextureUtilProvider TextureUtil;
|
||||
|
||||
public RuntimeProvider()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
SetupEvents();
|
||||
}
|
||||
|
||||
public static void Init() =>
|
||||
#if CPP
|
||||
Instance = new Il2Cpp.Il2CppProvider();
|
||||
#else
|
||||
Instance = new Mono.MonoProvider();
|
||||
#endif
|
||||
|
||||
|
||||
public abstract void Initialize();
|
||||
|
||||
public abstract void SetupEvents();
|
||||
|
||||
public abstract void StartConsoleCoroutine(IEnumerator routine);
|
||||
|
||||
// Unity API handlers
|
||||
|
||||
public abstract string LayerToName(int layer);
|
||||
|
||||
public abstract UnityEngine.Object[] FindObjectsOfTypeAll(Type type);
|
||||
|
||||
public abstract int GetSceneHandle(Scene scene);
|
||||
|
||||
public abstract GameObject[] GetRootGameObjects(Scene scene);
|
||||
|
||||
public abstract int GetRootCount(Scene scene);
|
||||
}
|
||||
}
|
160
src/Core/Runtime/TextureUtilProvider.cs
Normal file
160
src/Core/Runtime/TextureUtilProvider.cs
Normal file
@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
{
|
||||
public abstract class TextureUtilProvider
|
||||
{
|
||||
public static TextureUtilProvider Instance;
|
||||
|
||||
public TextureUtilProvider()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public abstract byte[] EncodeToPNG(Texture2D tex);
|
||||
|
||||
public abstract Texture2D NewTexture2D(int width, int height);
|
||||
|
||||
public abstract void Blit(Texture2D tex, RenderTexture rt);
|
||||
|
||||
public abstract bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable);
|
||||
|
||||
public abstract Sprite CreateSprite(Texture2D texture);
|
||||
|
||||
public static bool IsReadable(Texture2D tex)
|
||||
{
|
||||
try
|
||||
{
|
||||
// This will cause an exception if it's not readable.
|
||||
// Reason for doing it this way is not all Unity versions
|
||||
// ship with the 'Texture.isReadable' property.
|
||||
|
||||
tex.GetPixel(0, 0);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool LoadImage(Texture2D tex, string filePath, bool markNonReadable)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
return Instance.LoadImage(tex, File.ReadAllBytes(filePath), markNonReadable);
|
||||
}
|
||||
|
||||
public static Texture2D Copy(Texture2D orig, Rect rect)
|
||||
{
|
||||
Color[] pixels;
|
||||
|
||||
if (!IsReadable(orig))
|
||||
orig = ForceReadTexture(orig);
|
||||
|
||||
pixels = orig.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
|
||||
|
||||
Texture2D newTex = Instance.NewTexture2D((int)rect.width, (int)rect.height);
|
||||
|
||||
newTex.SetPixels(pixels);
|
||||
|
||||
return newTex;
|
||||
}
|
||||
|
||||
public static Texture2D ForceReadTexture(Texture2D tex)
|
||||
{
|
||||
try
|
||||
{
|
||||
FilterMode origFilter = tex.filterMode;
|
||||
tex.filterMode = FilterMode.Point;
|
||||
|
||||
var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32);
|
||||
rt.filterMode = FilterMode.Point;
|
||||
RenderTexture.active = rt;
|
||||
|
||||
Instance.Blit(tex, rt);
|
||||
|
||||
var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
|
||||
|
||||
_newTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
|
||||
_newTex.Apply(false, false);
|
||||
|
||||
RenderTexture.active = null;
|
||||
tex.filterMode = origFilter;
|
||||
|
||||
return _newTex;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log("Exception on ForceReadTexture: " + e.ToString());
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveTextureAsPNG(Texture2D tex, string dir, string name, bool isDTXnmNormal = false)
|
||||
{
|
||||
if (!Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
byte[] data;
|
||||
string savepath = dir + @"\" + name + ".png";
|
||||
|
||||
// Make sure we can EncodeToPNG it.
|
||||
if (tex.format != TextureFormat.ARGB32 || !IsReadable(tex))
|
||||
{
|
||||
tex = ForceReadTexture(tex);
|
||||
}
|
||||
|
||||
if (isDTXnmNormal)
|
||||
{
|
||||
tex = DTXnmToRGBA(tex);
|
||||
tex.Apply(false, false);
|
||||
}
|
||||
|
||||
data = Instance.EncodeToPNG(tex);
|
||||
|
||||
if (data == null || !data.Any())
|
||||
{
|
||||
ExplorerCore.LogWarning("Couldn't get any data for the texture!");
|
||||
}
|
||||
else
|
||||
{
|
||||
File.WriteAllBytes(savepath, data);
|
||||
}
|
||||
}
|
||||
|
||||
// Converts DTXnm-format Normal Map to RGBA-format Normal Map.
|
||||
public static Texture2D DTXnmToRGBA(Texture2D tex)
|
||||
{
|
||||
Color[] colors = tex.GetPixels();
|
||||
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
{
|
||||
var c = colors[i];
|
||||
|
||||
c.r = c.a * 2 - 1; // red <- alpha
|
||||
c.g = c.g * 2 - 1; // green is always the same
|
||||
|
||||
var rg = new Vector2(c.r, c.g); //this is the red-green vector
|
||||
c.b = Mathf.Sqrt(1 - Mathf.Clamp01(Vector2.Dot(rg, rg))); //recalculate the blue channel
|
||||
|
||||
colors[i] = new Color(
|
||||
(c.r * 0.5f) + 0.5f,
|
||||
(c.g * 0.5f) + 0.25f,
|
||||
(c.b * 0.5f) + 0.5f
|
||||
);
|
||||
}
|
||||
|
||||
var newtex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
|
||||
newtex.SetPixels(colors);
|
||||
|
||||
return newtex;
|
||||
}
|
||||
}
|
||||
}
|
206
src/Core/SceneExplorer.cs
Normal file
206
src/Core/SceneExplorer.cs
Normal file
@ -0,0 +1,206 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
using UnityExplorer.Core.Config;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class SceneExplorer
|
||||
{
|
||||
public static SceneExplorer Instance;
|
||||
|
||||
public static SceneExplorerUI UI;
|
||||
|
||||
internal static Action OnToggleShow;
|
||||
|
||||
public SceneExplorer()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
UI = new SceneExplorerUI();
|
||||
UI.ConstructScenePane();
|
||||
}
|
||||
|
||||
private const float UPDATE_INTERVAL = 1f;
|
||||
private float m_timeOfLastSceneUpdate;
|
||||
|
||||
// private int m_currentSceneHandle = -1;
|
||||
public static Scene DontDestroyScene => DontDestroyObject.scene;
|
||||
internal Scene m_currentScene;
|
||||
internal Scene[] m_currentScenes = new Scene[0];
|
||||
|
||||
internal GameObject[] m_allObjects = new GameObject[0];
|
||||
|
||||
internal GameObject m_selectedSceneObject;
|
||||
internal int m_lastCount;
|
||||
|
||||
internal static GameObject DontDestroyObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!s_dontDestroyObject)
|
||||
{
|
||||
s_dontDestroyObject = new GameObject("DontDestroyMe");
|
||||
GameObject.DontDestroyOnLoad(s_dontDestroyObject);
|
||||
}
|
||||
return s_dontDestroyObject;
|
||||
}
|
||||
}
|
||||
internal static GameObject s_dontDestroyObject;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
RefreshSceneSelector();
|
||||
|
||||
if (ExplorerConfig.Instance.SceneExplorer_Hidden)
|
||||
UI.ToggleShow();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (UI.Hiding || Time.realtimeSinceStartup - m_timeOfLastSceneUpdate < UPDATE_INTERVAL)
|
||||
return;
|
||||
|
||||
RefreshSceneSelector();
|
||||
|
||||
if (!m_selectedSceneObject)
|
||||
{
|
||||
if (m_currentScene != default)
|
||||
{
|
||||
var rootObjects = RuntimeProvider.Instance.GetRootGameObjects(m_currentScene);
|
||||
SetSceneObjectList(rootObjects);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshSelectedSceneObject();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshSceneSelector()
|
||||
{
|
||||
var newNames = new List<string>();
|
||||
var newScenes = new List<Scene>();
|
||||
|
||||
if (m_currentScenes == null)
|
||||
m_currentScenes = new Scene[0];
|
||||
|
||||
bool anyChange = SceneManager.sceneCount != m_currentScenes.Length - 1;
|
||||
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
Scene scene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (scene == default)
|
||||
continue;
|
||||
|
||||
int handle = RuntimeProvider.Instance.GetSceneHandle(scene);
|
||||
|
||||
if (!anyChange && !m_currentScenes.Any(it => handle == RuntimeProvider.Instance.GetSceneHandle(it)))
|
||||
anyChange = true;
|
||||
|
||||
newScenes.Add(scene);
|
||||
newNames.Add(scene.name);
|
||||
}
|
||||
|
||||
if (anyChange)
|
||||
{
|
||||
newNames.Add("DontDestroyOnLoad");
|
||||
newScenes.Add(DontDestroyScene);
|
||||
m_currentScenes = newScenes.ToArray();
|
||||
|
||||
UI.OnActiveScenesChanged(newNames);
|
||||
|
||||
SetTargetScene(newScenes[0]);
|
||||
|
||||
SearchPage.Instance.OnSceneChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTargetScene(int index)
|
||||
=> SetTargetScene(m_currentScenes[index]);
|
||||
|
||||
public void SetTargetScene(Scene scene)
|
||||
{
|
||||
if (scene == default)
|
||||
return;
|
||||
|
||||
m_currentScene = scene;
|
||||
var rootObjs = RuntimeProvider.Instance.GetRootGameObjects(scene);
|
||||
SetSceneObjectList(rootObjs);
|
||||
|
||||
m_selectedSceneObject = null;
|
||||
|
||||
UI.OnSceneSelected();
|
||||
}
|
||||
|
||||
public void SetSceneObjectParent()
|
||||
{
|
||||
if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent?.gameObject)
|
||||
{
|
||||
m_selectedSceneObject = null;
|
||||
SetTargetScene(m_currentScene);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTargetObject(m_selectedSceneObject.transform.parent.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTargetObject(GameObject obj)
|
||||
{
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
UI.OnGameObjectSelected(obj);
|
||||
|
||||
m_selectedSceneObject = obj;
|
||||
|
||||
RefreshSelectedSceneObject();
|
||||
}
|
||||
|
||||
private void RefreshSelectedSceneObject()
|
||||
{
|
||||
GameObject[] list = new GameObject[m_selectedSceneObject.transform.childCount];
|
||||
for (int i = 0; i < m_selectedSceneObject.transform.childCount; i++)
|
||||
{
|
||||
list[i] = m_selectedSceneObject.transform.GetChild(i).gameObject;
|
||||
}
|
||||
|
||||
SetSceneObjectList(list);
|
||||
}
|
||||
|
||||
private void SetSceneObjectList(GameObject[] objects)
|
||||
{
|
||||
m_allObjects = objects;
|
||||
RefreshSceneObjectList();
|
||||
}
|
||||
|
||||
internal void RefreshSceneObjectList()
|
||||
{
|
||||
m_timeOfLastSceneUpdate = Time.realtimeSinceStartup;
|
||||
|
||||
UI.RefreshSceneObjectList(m_allObjects, out int newCount);
|
||||
|
||||
m_lastCount = newCount;
|
||||
}
|
||||
|
||||
internal static void InspectSelectedGameObject()
|
||||
{
|
||||
InspectorManager.Instance.Inspect(Instance.m_selectedSceneObject);
|
||||
}
|
||||
|
||||
internal static void InvokeOnToggleShow()
|
||||
{
|
||||
OnToggleShow?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
14
src/Core/Search/ChildFilter.cs
Normal file
14
src/Core/Search/ChildFilter.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
internal enum ChildFilter
|
||||
{
|
||||
Any,
|
||||
RootObject,
|
||||
HasParent
|
||||
}
|
||||
}
|
15
src/Core/Search/SceneFilter.cs
Normal file
15
src/Core/Search/SceneFilter.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
internal enum SceneFilter
|
||||
{
|
||||
Any,
|
||||
Asset,
|
||||
DontDestroyOnLoad,
|
||||
Explicit,
|
||||
}
|
||||
}
|
17
src/Core/Search/SearchContext.cs
Normal file
17
src/Core/Search/SearchContext.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
internal enum SearchContext
|
||||
{
|
||||
UnityObject,
|
||||
GameObject,
|
||||
Component,
|
||||
Custom,
|
||||
Singleton,
|
||||
StaticClass
|
||||
}
|
||||
}
|
227
src/Core/Search/SearchProvider.cs
Normal file
227
src/Core/Search/SearchProvider.cs
Normal file
@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
public static class SearchProvider
|
||||
{
|
||||
internal static object[] StaticClassSearch(string input)
|
||||
{
|
||||
var list = new List<Type>();
|
||||
|
||||
var nameFilter = "";
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
nameFilter = input.ToLower();
|
||||
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var type in asm.TryGetTypes().Where(it => it.IsSealed && it.IsAbstract))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
list.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
internal static string[] s_instanceNames = new string[]
|
||||
{
|
||||
"m_instance",
|
||||
"m_Instance",
|
||||
"s_instance",
|
||||
"s_Instance",
|
||||
"_instance",
|
||||
"_Instance",
|
||||
"instance",
|
||||
"Instance",
|
||||
"<Instance>k__BackingField",
|
||||
"<instance>k__BackingField",
|
||||
};
|
||||
|
||||
internal static object[] SingletonSearch(string input)
|
||||
{
|
||||
var instances = new List<object>();
|
||||
|
||||
var nameFilter = "";
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
nameFilter = input.ToLower();
|
||||
|
||||
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
|
||||
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
// Search all non-static, non-enum classes.
|
||||
foreach (var type in asm.TryGetTypes().Where(it => !(it.IsSealed && it.IsAbstract) && !it.IsEnum))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
#if CPP
|
||||
// Only look for Properties in IL2CPP, not for Mono.
|
||||
PropertyInfo pi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
pi = type.GetProperty(name, flags);
|
||||
if (pi != null)
|
||||
{
|
||||
var instance = pi.GetValue(null, null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Look for a typical Instance backing field.
|
||||
FieldInfo fi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
fi = type.GetField(name, flags);
|
||||
if (fi != null)
|
||||
{
|
||||
var instance = fi.GetValue(null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
return instances.ToArray();
|
||||
}
|
||||
|
||||
internal static object[] UnityObjectSearch(string input, string customTypeInput, SearchContext context,
|
||||
ChildFilter childFilter, SceneFilter sceneFilter)
|
||||
{
|
||||
Type searchType = null;
|
||||
switch (context)
|
||||
{
|
||||
case SearchContext.GameObject:
|
||||
searchType = typeof(GameObject); break;
|
||||
|
||||
case SearchContext.Component:
|
||||
searchType = typeof(Component); break;
|
||||
|
||||
case SearchContext.Custom:
|
||||
if (string.IsNullOrEmpty(customTypeInput))
|
||||
{
|
||||
ExplorerCore.LogWarning("Custom Type input must not be empty!");
|
||||
return null;
|
||||
}
|
||||
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
|
||||
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
|
||||
searchType = customType;
|
||||
else
|
||||
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
|
||||
else
|
||||
ExplorerCore.LogWarning($"Could not find a type by the name '{customTypeInput}'!");
|
||||
break;
|
||||
|
||||
default:
|
||||
searchType = typeof(UnityEngine.Object); break;
|
||||
}
|
||||
|
||||
if (searchType == null)
|
||||
return null;
|
||||
|
||||
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(searchType);
|
||||
var results = new List<object>();
|
||||
|
||||
// perform filter comparers
|
||||
|
||||
string nameFilter = null;
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
nameFilter = input.ToLower();
|
||||
|
||||
bool canGetGameObject = (sceneFilter != SceneFilter.Any || childFilter != ChildFilter.Any)
|
||||
&& (context == SearchContext.GameObject || typeof(Component).IsAssignableFrom(searchType));
|
||||
|
||||
string sceneFilterString = null;
|
||||
if (!canGetGameObject)
|
||||
{
|
||||
if (context != SearchContext.UnityObject && (sceneFilter != SceneFilter.Any || childFilter != ChildFilter.Any))
|
||||
ExplorerCore.LogWarning($"Type '{searchType}' cannot have Scene or Child filters applied to it");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sceneFilter == SceneFilter.DontDestroyOnLoad)
|
||||
sceneFilterString = "DontDestroyOnLoad";
|
||||
else if (sceneFilter == SceneFilter.Explicit)
|
||||
sceneFilterString = SearchPage.Instance.m_sceneDropdown.options[SearchPage.Instance.m_sceneDropdown.value].text;
|
||||
}
|
||||
|
||||
foreach (var obj in allObjects)
|
||||
{
|
||||
// name check
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
if (canGetGameObject)
|
||||
{
|
||||
#if MONO
|
||||
var go = context == SearchContext.GameObject
|
||||
? obj as GameObject
|
||||
: (obj as Component).gameObject;
|
||||
#else
|
||||
var go = context == SearchContext.GameObject
|
||||
? obj.TryCast<GameObject>()
|
||||
: obj.TryCast<Component>().gameObject;
|
||||
#endif
|
||||
|
||||
// scene check
|
||||
if (sceneFilter != SceneFilter.Any)
|
||||
{
|
||||
if (!go)
|
||||
continue;
|
||||
|
||||
switch (context)
|
||||
{
|
||||
case SearchContext.GameObject:
|
||||
if (go.scene.name != sceneFilterString)
|
||||
continue;
|
||||
break;
|
||||
case SearchContext.Custom:
|
||||
case SearchContext.Component:
|
||||
if (go.scene.name != sceneFilterString)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (childFilter != ChildFilter.Any)
|
||||
{
|
||||
if (!go)
|
||||
continue;
|
||||
|
||||
// root object check (no parent)
|
||||
if (childFilter == ChildFilter.HasParent && !go.transform.parent)
|
||||
continue;
|
||||
else if (childFilter == ChildFilter.RootObject && go.transform.parent)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(obj);
|
||||
}
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
290
src/Core/Tests/Tests.cs
Normal file
290
src/Core/Tests/Tests.cs
Normal file
@ -0,0 +1,290 @@
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using UnityExplorer.UI;
|
||||
//using UnityEngine;
|
||||
//using System;
|
||||
//using System.Runtime.InteropServices;
|
||||
//using System.Text;
|
||||
//using UnityExplorer.Core.Runtime;
|
||||
|
||||
//namespace UnityExplorer.Core.Tests
|
||||
//{
|
||||
// internal enum TestByteEnum : byte
|
||||
// {
|
||||
// One,
|
||||
// Two,
|
||||
// Three,
|
||||
// TwoFiftyFive = 255,
|
||||
// }
|
||||
|
||||
// public static class StaticTestClass
|
||||
// {
|
||||
// public static int StaticProperty => 5;
|
||||
// public static int StaticField = 69;
|
||||
// public static List<string> StaticList = new List<string>
|
||||
// {
|
||||
// "one",
|
||||
// "two",
|
||||
// "three",
|
||||
// };
|
||||
// public static void StaticMethod() { }
|
||||
// }
|
||||
|
||||
// public class TestClass
|
||||
// {
|
||||
// internal static TestByteEnum testingByte = TestByteEnum.One;
|
||||
|
||||
// public string AAALongString = @"1
|
||||
//2
|
||||
//3
|
||||
//4
|
||||
//5";
|
||||
|
||||
// public Vector2 AATestVector2 = new Vector2(1, 2);
|
||||
// public Vector3 AATestVector3 = new Vector3(1, 2, 3);
|
||||
// public Vector4 AATestVector4 = new Vector4(1, 2, 3, 4);
|
||||
// public Rect AATestRect = new Rect(1, 2, 3, 4);
|
||||
// public Color AATestColor = new Color(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
|
||||
// public bool ATestBoolMethod() => false;
|
||||
|
||||
// public bool this[int index]
|
||||
// {
|
||||
// get => index % 2 == 0;
|
||||
// set => m_thisBool = value;
|
||||
// }
|
||||
// internal bool m_thisBool;
|
||||
|
||||
// static int testInt;
|
||||
// public static List<string> ExceptionList
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// testInt++;
|
||||
// if (testInt % 2 == 0)
|
||||
// throw new Exception("its even");
|
||||
// else
|
||||
// return new List<string> { "one" };
|
||||
// }
|
||||
// }
|
||||
|
||||
// static bool abool;
|
||||
// public static bool ATestExceptionBool
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// abool = !abool;
|
||||
// if (!abool)
|
||||
// throw new Exception("false");
|
||||
// else
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static string ExceptionString => throw new NotImplementedException();
|
||||
|
||||
// public static string ANullString = null;
|
||||
// public static float ATestFloat = 420.69f;
|
||||
// public static int ATestInt = -1;
|
||||
// public static string ATestString = "hello world";
|
||||
// public static uint ATestUInt = 1u;
|
||||
// public static byte ATestByte = 255;
|
||||
// public static ulong AReadonlyUlong = 82934UL;
|
||||
|
||||
// public static TestClass Instance => m_instance ?? (m_instance = new TestClass());
|
||||
// private static TestClass m_instance;
|
||||
|
||||
// public object AmbigObject;
|
||||
|
||||
// public List<List<List<string>>> ANestedNestedList = new List<List<List<string>>>
|
||||
// {
|
||||
// new List<List<string>>
|
||||
// {
|
||||
// new List<string>
|
||||
// {
|
||||
// "one",
|
||||
// "two",
|
||||
// },
|
||||
// new List<string>
|
||||
// {
|
||||
// "three",
|
||||
// "four"
|
||||
// }
|
||||
// },
|
||||
// new List<List<string>>
|
||||
// {
|
||||
// new List<string>
|
||||
// {
|
||||
// "five",
|
||||
// "six"
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// public static bool SetOnlyProperty
|
||||
// {
|
||||
// set => m_setOnlyProperty = value;
|
||||
// }
|
||||
// private static bool m_setOnlyProperty;
|
||||
// public static bool ReadSetOnlyProperty => m_setOnlyProperty;
|
||||
|
||||
// public Texture2D TestTexture;
|
||||
// public static Sprite TestSprite;
|
||||
|
||||
//#if CPP
|
||||
// public static Il2CppSystem.Collections.Generic.HashSet<string> CppHashSetTest;
|
||||
// public static Il2CppSystem.Collections.Generic.List<string> CppStringTest;
|
||||
// public static Il2CppSystem.Collections.IList CppIList;
|
||||
// //public static Il2CppSystem.Collections.Generic.Dictionary<string, string> CppDictTest;
|
||||
// //public static Il2CppSystem.Collections.Generic.Dictionary<int, float> CppDictTest2;
|
||||
//#endif
|
||||
|
||||
// public TestClass()
|
||||
// {
|
||||
// int a = 0;
|
||||
// foreach (var list in ANestedNestedList)
|
||||
// {
|
||||
// foreach (var list2 in list)
|
||||
// {
|
||||
// for (int i = 0; i < 33; i++)
|
||||
// list2.Add(a++.ToString());
|
||||
// }
|
||||
// }
|
||||
|
||||
//#if CPP
|
||||
// //TextureSpriteTest();
|
||||
|
||||
// CppHashSetTest = new Il2CppSystem.Collections.Generic.HashSet<string>();
|
||||
// CppHashSetTest.Add("1");
|
||||
// CppHashSetTest.Add("2");
|
||||
// CppHashSetTest.Add("3");
|
||||
|
||||
// CppStringTest = new Il2CppSystem.Collections.Generic.List<string>();
|
||||
// CppStringTest.Add("1");
|
||||
// CppStringTest.Add("2");
|
||||
|
||||
// //CppDictTest = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
|
||||
// //CppDictTest.Add("key1", "value1");
|
||||
// //CppDictTest.Add("key2", "value2");
|
||||
// //CppDictTest.Add("key3", "value3");
|
||||
|
||||
// //CppDictTest2 = new Il2CppSystem.Collections.Generic.Dictionary<int, float>();
|
||||
// //CppDictTest2.Add(0, 0.5f);
|
||||
// //CppDictTest2.Add(1, 0.5f);
|
||||
// //CppDictTest2.Add(2, 0.5f);
|
||||
//#endif
|
||||
// }
|
||||
|
||||
// //private void TextureSpriteTest()
|
||||
// //{
|
||||
// // TestTexture = new Texture2D(32, 32, TextureFormat.ARGB32, false)
|
||||
// // {
|
||||
// // name = "TestTexture"
|
||||
// // };
|
||||
// // TestSprite = TextureUtilProvider.Instance.CreateSprite(TestTexture);
|
||||
|
||||
// // GameObject.DontDestroyOnLoad(TestTexture);
|
||||
// // GameObject.DontDestroyOnLoad(TestSprite);
|
||||
|
||||
// // // test loading a tex from file
|
||||
// // if (System.IO.File.Exists(@"D:\Downloads\test.png"))
|
||||
// // {
|
||||
// // var dataToLoad = System.IO.File.ReadAllBytes(@"D:\Downloads\test.png");
|
||||
// // ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}");
|
||||
// // }
|
||||
// //}
|
||||
|
||||
// //public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
|
||||
// //{
|
||||
// // arg2 = "this is arg2";
|
||||
|
||||
// // return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
|
||||
// //}
|
||||
|
||||
// // test a non-generic dictionary
|
||||
|
||||
// public Hashtable TestNonGenericDict()
|
||||
// {
|
||||
// return new Hashtable
|
||||
// {
|
||||
// { "One", 1 },
|
||||
// { "Two", 2 },
|
||||
// { "Three", 3 },
|
||||
// };
|
||||
// }
|
||||
|
||||
// // test HashSets
|
||||
|
||||
// public static HashSet<string> HashSetTest = new HashSet<string>
|
||||
// {
|
||||
// "One",
|
||||
// "Two",
|
||||
// "Three"
|
||||
// };
|
||||
|
||||
|
||||
// // Test indexed parameter
|
||||
|
||||
// public string this[int arg0, string arg1]
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return $"arg0: {arg0}, arg1: {arg1}";
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Test basic list
|
||||
|
||||
// public static List<string> TestList = new List<string>
|
||||
// {
|
||||
// "1",
|
||||
// "2",
|
||||
// "3",
|
||||
// "etc..."
|
||||
// };
|
||||
|
||||
// // Test a nested dictionary
|
||||
|
||||
// public static Dictionary<int, Dictionary<string, int>> NestedDictionary = new Dictionary<int, Dictionary<string, int>>
|
||||
// {
|
||||
// {
|
||||
// 1,
|
||||
// new Dictionary<string, int>
|
||||
// {
|
||||
// {
|
||||
// "Sub 1", 123
|
||||
// },
|
||||
// {
|
||||
// "Sub 2", 456
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// 2,
|
||||
// new Dictionary<string, int>
|
||||
// {
|
||||
// {
|
||||
// "Sub 3", 789
|
||||
// },
|
||||
// {
|
||||
// "Sub 4", 000
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// };
|
||||
|
||||
// // Test a basic method
|
||||
|
||||
// public static Color TestMethod(float r, float g, float b, float a)
|
||||
// {
|
||||
// return new Color(r, g, b, a);
|
||||
// }
|
||||
|
||||
// // A method with default arguments
|
||||
|
||||
// public static Vector3 TestDefaultArgs(float arg0, float arg1, float arg2 = 5.0f)
|
||||
// {
|
||||
// return new Vector3(arg0, arg1, arg2);
|
||||
// }
|
||||
// }
|
||||
//}
|
46
src/Core/Unity/ColorHelper.cs
Normal file
46
src/Core/Unity/ColorHelper.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Unity
|
||||
{
|
||||
public static class ColorHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts Color to 6-digit RGB hex code (without # symbol). Eg, RGBA(1,0,0,1) -> FF0000
|
||||
/// </summary>
|
||||
public static string ToHex(this Color color)
|
||||
{
|
||||
byte r = (byte)Mathf.Clamp(Mathf.RoundToInt(color.r * 255f), 0, 255);
|
||||
byte g = (byte)Mathf.Clamp(Mathf.RoundToInt(color.g * 255f), 0, 255);
|
||||
byte b = (byte)Mathf.Clamp(Mathf.RoundToInt(color.b * 255f), 0, 255);
|
||||
|
||||
return $"{r:X2}{g:X2}{b:X2}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assumes the string is a 6-digit RGB Hex color code, which it will parse into a UnityEngine.Color.
|
||||
/// Eg, FF0000 -> RGBA(1,0,0,1)
|
||||
/// </summary>
|
||||
public static Color ToColor(this string _string)
|
||||
{
|
||||
_string = _string.Replace("#", "");
|
||||
|
||||
if (_string.Length != 6)
|
||||
return Color.magenta;
|
||||
|
||||
var r = byte.Parse(_string.Substring(0, 2), NumberStyles.HexNumber);
|
||||
var g = byte.Parse(_string.Substring(2, 2), NumberStyles.HexNumber);
|
||||
var b = byte.Parse(_string.Substring(4, 2), NumberStyles.HexNumber);
|
||||
|
||||
var color = new Color
|
||||
{
|
||||
r = (float)(r / (decimal)255),
|
||||
g = (float)(g / (decimal)255),
|
||||
b = (float)(b / (decimal)255),
|
||||
a = 1
|
||||
};
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
62
src/Core/Unity/UnityHelper.cs
Normal file
62
src/Core/Unity/UnityHelper.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Unity
|
||||
{
|
||||
public static class UnityHelper
|
||||
{
|
||||
private static Camera m_mainCamera;
|
||||
|
||||
public static Camera MainCamera
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_mainCamera)
|
||||
{
|
||||
m_mainCamera = Camera.main;
|
||||
}
|
||||
return m_mainCamera;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = true)
|
||||
{
|
||||
var unityObj = obj as Object;
|
||||
if (obj == null)
|
||||
{
|
||||
if (!suppressWarning)
|
||||
ExplorerCore.LogWarning("The target instance is null!");
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (obj is Object)
|
||||
{
|
||||
if (!unityObj)
|
||||
{
|
||||
if (!suppressWarning)
|
||||
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string ToStringLong(this Vector3 vec)
|
||||
{
|
||||
return $"{vec.x:F3}, {vec.y:F3}, {vec.z:F3}";
|
||||
}
|
||||
|
||||
public static string GetTransformPath(this Transform t, bool includeThisName = false)
|
||||
{
|
||||
string path = includeThisName ? t.transform.name : "";
|
||||
|
||||
while (t.parent != null)
|
||||
{
|
||||
t = t.parent;
|
||||
path = $"{t.name}/{path}";
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Release_ML_Cpp</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
<OutputPath>..\Release\Explorer.MelonLoader.Il2Cpp\</OutputPath>
|
||||
<DefineConstants>CPP,ML</DefineConstants>
|
||||
<IsCpp>true</IsCpp>
|
||||
<IsMelonLoader>true</IsMelonLoader>
|
||||
<IsNet35>false</IsNet35>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<RootNamespace>Explorer</RootNamespace>
|
||||
<AssemblyName>Explorer</AssemblyName>
|
||||
<!-- Set this to the MelonLoader Il2Cpp Game folder, without the ending '\' character. -->
|
||||
<MLCppGameFolder>D:\Steam\steamapps\common\Hellpoint</MLCppGameFolder>
|
||||
<!--<MLCppGameFolder>D:\source\Unity Projects\Test\_BUILD</MLCppGameFolder>-->
|
||||
<!-- Set this to the MelonLoader Mono Game folder, without the ending '\' character. -->
|
||||
<MLMonoGameFolder>D:\Steam\steamapps\common\Outward</MLMonoGameFolder>
|
||||
<!-- Set this to the BepInEx Il2Cpp Game folder, without the ending '\' character. -->
|
||||
<BIECppGameFolder>D:\Steam\steamapps\common\Outward - Il2Cpp</BIECppGameFolder>
|
||||
<!-- Set this to the BepInEx Mono Game folder, without the ending '\' character. -->
|
||||
<BIEMonoGameFolder>D:\Steam\steamapps\common\Outward</BIEMonoGameFolder>
|
||||
<!-- <BIEMonoGameFolder>D:\source\Unity Projects\! My Unity Games\NewInputSystemTest\_BUILD</BIEMonoGameFolder> -->
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_ML_Cpp|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<OutputPath>..\Release\Explorer.MelonLoader.Il2Cpp\</OutputPath>
|
||||
<DefineConstants>CPP,ML</DefineConstants>
|
||||
<IsCpp>true</IsCpp>
|
||||
<IsMelonLoader>true</IsMelonLoader>
|
||||
<IsNet35>false</IsNet35>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_ML_Mono|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<OutputPath>..\Release\Explorer.MelonLoader.Mono\</OutputPath>
|
||||
<DefineConstants>MONO,ML</DefineConstants>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<IsCpp>false</IsCpp>
|
||||
<IsMelonLoader>true</IsMelonLoader>
|
||||
<IsNet35>false</IsNet35>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_ML_Mono_NET35|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<OutputPath>..\Release\Explorer.MelonLoader.Mono.NET35\</OutputPath>
|
||||
<DefineConstants>MONO,ML,NET35</DefineConstants>
|
||||
<IsCpp>false</IsCpp>
|
||||
<IsMelonLoader>true</IsMelonLoader>
|
||||
<IsNet35>true</IsNet35>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_BIE_Cpp|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<OutputPath>..\Release\Explorer.BepInEx.Il2Cpp\</OutputPath>
|
||||
<DefineConstants>CPP,BIE</DefineConstants>
|
||||
<IsCpp>true</IsCpp>
|
||||
<IsMelonLoader>false</IsMelonLoader>
|
||||
<IsNet35>false</IsNet35>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_BIE_Mono|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<OutputPath>..\Release\Explorer.BepInEx.Mono\</OutputPath>
|
||||
<DefineConstants>MONO,BIE</DefineConstants>
|
||||
<IsCpp>false</IsCpp>
|
||||
<IsMelonLoader>false</IsMelonLoader>
|
||||
<IsNet35>false</IsNet35>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_BIE_Mono_NET35|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<OutputPath>..\Release\Explorer.BepInEx.Mono.NET35\</OutputPath>
|
||||
<DefineConstants>MONO,BIE,NET35</DefineConstants>
|
||||
<IsCpp>false</IsCpp>
|
||||
<IsMelonLoader>false</IsMelonLoader>
|
||||
<IsNet35>true</IsNet35>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<!-- MCS ref -->
|
||||
<Reference Include="mcs" Condition="'$(IsNet35)'=='false'">
|
||||
<HintPath>..\lib\mcs.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="mcs" Condition="'$(IsNet35)'=='true'">
|
||||
<HintPath>..\lib\mcs.NET35.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- Universal Mono UnityEngine.dll ref (v5.3) -->
|
||||
<ItemGroup Condition="'$(IsCpp)'=='false'">
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>..\lib\UnityEngine.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- MelonLoader Mono ref -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)|$(IsCpp)'=='true|false'">
|
||||
<Reference Include="MelonLoader.ModHandler">
|
||||
<HintPath>$(MLMonoGameFolder)\MelonLoader\MelonLoader.ModHandler.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- BepInEx Mono refs -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)|$(IsCpp)'=='false|false'">
|
||||
<Reference Include="BepInEx">
|
||||
<HintPath>$(BIEMonoGameFolder)\BepInEx\core\BepInEx.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>$(BIEMonoGameFolder)\BepInEx\core\0Harmony.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- MelonLoader Il2Cpp refs -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)|$(IsCpp)'=='true|true'">
|
||||
<Reference Include="MelonLoader.ModHandler">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\MelonLoader.ModHandler.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnhollowerBaseLib">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Il2Cppmscorlib">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Il2CppSystem.Core">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\Il2CppSystem.Core.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.IMGUIModule">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.IMGUIModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TextRenderingModule">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>$(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- BepInEx Il2Cpp refs -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)|$(IsCpp)'=='false|true'">
|
||||
<Reference Include="BepInEx">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\core\BepInEx.Core.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\core\0Harmony.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="BepInEx.IL2CPP">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\core\BepInEx.IL2CPP.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnhollowerBaseLib">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\core\UnhollowerBaseLib.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Il2Cppmscorlib">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\Il2Cppmscorlib.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Il2CppSystem.Core">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\Il2CppSystem.Core.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.CoreModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.IMGUIModule">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.IMGUIModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TextRenderingModule">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.TextRenderingModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>$(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.UI.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CachedObjects\CacheFactory.cs" />
|
||||
<Compile Include="CachedObjects\IExpandHeight.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheColor.cs" />
|
||||
<Compile Include="CachedObjects\Object\CacheDictionary.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheEnum.cs" />
|
||||
<Compile Include="CachedObjects\Object\CacheGameObject.cs" />
|
||||
<Compile Include="CachedObjects\Object\CacheList.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheEnumFlags.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CachePrimitive.cs" />
|
||||
<Compile Include="CachedObjects\Other\CacheOther.cs" />
|
||||
<Compile Include="CachedObjects\Other\CacheMethod.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheQuaternion.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheVector.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheRect.cs" />
|
||||
<Compile Include="Config\ModConfig.cs" />
|
||||
<Compile Include="ExplorerCore.cs" />
|
||||
<Compile Include="ExplorerBepInPlugin.cs" />
|
||||
<Compile Include="ExplorerMelonMod.cs" />
|
||||
<Compile Include="Extensions\ReflectionExtensions.cs" />
|
||||
<Compile Include="Helpers\InputHelper.cs" />
|
||||
<Compile Include="Menu\CursorControl.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\OptionsPage.cs" />
|
||||
<Compile Include="Tests\TestClass.cs" />
|
||||
<Compile Include="UnstripFixes\GUIUnstrip.cs" />
|
||||
<Compile Include="UnstripFixes\Internal_LayoutUtility.cs" />
|
||||
<Compile Include="Extensions\UnityExtensions.cs" />
|
||||
<Compile Include="Helpers\PageHelper.cs" />
|
||||
<Compile Include="Helpers\ReflectionHelpers.cs" />
|
||||
<Compile Include="Menu\UIHelpers.cs" />
|
||||
<Compile Include="Helpers\UnityHelpers.cs" />
|
||||
<Compile Include="Menu\InspectUnderMouse.cs" />
|
||||
<Compile Include="CachedObjects\CacheObjectBase.cs" />
|
||||
<Compile Include="UnstripFixes\Internal_ScrollViewState.cs" />
|
||||
<Compile Include="UnstripFixes\Internal_SliderHandler.cs" />
|
||||
<Compile Include="Menu\ResizeDrag.cs" />
|
||||
<Compile Include="Menu\Windows\TabViewWindow.cs" />
|
||||
<Compile Include="Menu\Windows\UIWindow.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\ConsolePage.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\Console\REPL.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\Console\REPLHelper.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\WindowPage.cs" />
|
||||
<Compile Include="Menu\Windows\WindowManager.cs" />
|
||||
<Compile Include="Menu\MainMenu\MainMenu.cs" />
|
||||
<Compile Include="Menu\Windows\GameObjectWindow.cs" />
|
||||
<Compile Include="Menu\Windows\ReflectionWindow.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\ScenePage.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\SearchPage.cs" />
|
||||
<Compile Include="Menu\UIStyles.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UnstripFixes\Internal.cs" />
|
||||
<Compile Include="UnstripFixes\Internal_SliderState.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@ -1,122 +0,0 @@
|
||||
#if BIE
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using BepInEx;
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
#if CPP
|
||||
using UnhollowerRuntimeLib;
|
||||
using BepInEx.IL2CPP;
|
||||
#endif
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
[BepInPlugin(ExplorerCore.GUID, ExplorerCore.NAME, ExplorerCore.VERSION)]
|
||||
#if CPP
|
||||
public class ExplorerBepInPlugin : BasePlugin
|
||||
#else
|
||||
public class ExplorerBepInPlugin : BaseUnityPlugin
|
||||
#endif
|
||||
{
|
||||
public static ExplorerBepInPlugin Instance;
|
||||
|
||||
public static ManualLogSource Logging =>
|
||||
#if CPP
|
||||
Instance?.Log;
|
||||
#else
|
||||
Instance?.Logger;
|
||||
#endif
|
||||
|
||||
public static readonly Harmony HarmonyInstance = new Harmony(ExplorerCore.GUID);
|
||||
|
||||
#if CPP
|
||||
// temporary for Il2Cpp until scene change delegate works
|
||||
private static string lastSceneName;
|
||||
#endif
|
||||
|
||||
// Init
|
||||
#if CPP
|
||||
public override void Load()
|
||||
{
|
||||
#else
|
||||
internal void Awake()
|
||||
{
|
||||
#endif
|
||||
Instance = this;
|
||||
|
||||
#if CPP
|
||||
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
|
||||
|
||||
var obj = new GameObject(
|
||||
"ExplorerBehaviour",
|
||||
new Il2CppSystem.Type[]
|
||||
{
|
||||
Il2CppType.Of<ExplorerBehaviour>()
|
||||
}
|
||||
);
|
||||
GameObject.DontDestroyOnLoad(obj);
|
||||
#else
|
||||
SceneManager.activeSceneChanged += DoSceneChange;
|
||||
#endif
|
||||
|
||||
LoadMCS();
|
||||
|
||||
new ExplorerCore();
|
||||
|
||||
//HarmonyInstance.PatchAll();
|
||||
}
|
||||
|
||||
void LoadMCS()
|
||||
{
|
||||
#if NET35
|
||||
var path = @"BepInEx\plugins\mcs.NET35.dll";
|
||||
#else
|
||||
var path = @"BepInEx\plugins\mcs.dll";
|
||||
#endif
|
||||
Assembly.Load(File.ReadAllBytes(path));
|
||||
ExplorerCore.Log("Loaded mcs!");
|
||||
}
|
||||
|
||||
internal static void DoSceneChange(Scene arg0, Scene arg1)
|
||||
{
|
||||
ExplorerCore.OnSceneChange();
|
||||
}
|
||||
|
||||
#if CPP // BepInEx Il2Cpp mod class doesn't have monobehaviour methods yet, so wrap them in a dummy.
|
||||
public class ExplorerBehaviour : MonoBehaviour
|
||||
{
|
||||
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
||||
|
||||
internal void Awake()
|
||||
{
|
||||
Logging.LogMessage("ExplorerBehaviour.Awake");
|
||||
}
|
||||
|
||||
#endif
|
||||
internal void Update()
|
||||
{
|
||||
ExplorerCore.Update();
|
||||
|
||||
#if CPP
|
||||
var scene = SceneManager.GetActiveScene();
|
||||
if (scene.name != lastSceneName)
|
||||
{
|
||||
lastSceneName = scene.name;
|
||||
DoSceneChange(scene, scene);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void OnGUI()
|
||||
{
|
||||
ExplorerCore.OnGUI();
|
||||
}
|
||||
#if CPP
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user