Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some rare enum detection bugs #2808

Merged
merged 2 commits into from Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion decompiler/IR2/AtomicOpTypeAnalysis.cpp
Expand Up @@ -745,7 +745,7 @@ TP_Type SimpleExpression::get_type_int2(const TypeState& input,

// allow shifting stuff for setting bitfields
if (m_kind == Kind::LEFT_SHIFT) {
return TP_Type::make_from_ts("int");
return TP_Type::make_from_ts(TypeSpec("int"));
}

throw std::runtime_error(fmt::format("Cannot get_type_int2: {}, args {} and {}",
Expand Down
31 changes: 25 additions & 6 deletions decompiler/IR2/FormExpressionAnalysis.cpp
Expand Up @@ -4658,8 +4658,8 @@ FormElement* try_make_nonzero_logtest(Form* in, FormPool& pool) {
`(nonzero? (logand ,a ,b))
)
*/
auto logand_matcher = Matcher::op(GenericOpMatcher::fixed(FixedOperatorKind::LOGAND),
{Matcher::any(0), Matcher::any(1)});
auto static const logand_matcher = Matcher::op(GenericOpMatcher::fixed(FixedOperatorKind::LOGAND),
{Matcher::any(0), Matcher::any(1)});
auto mr_logand = match(logand_matcher, in);
if (mr_logand.matched) {
return pool.alloc_element<GenericElement>(
Expand Down Expand Up @@ -4744,13 +4744,25 @@ FormElement* try_make_logtest_cpad_macro(Form* in, FormPool& pool) {
`(logtest? (cpad-hold ,pad-idx) (pad-buttons ,@buttons))
)
*/
auto cpad_matcher = Matcher::op(
auto static const cpad_matcher = Matcher::op(
GenericOpMatcher::fixed(FixedOperatorKind::LOGTEST),
{Matcher::deref(Matcher::symbol("*cpad-list*"), false,
{DerefTokenMatcher::string("cpads"), DerefTokenMatcher::any_expr_or_int(0),
DerefTokenMatcher::any_string(2), DerefTokenMatcher::integer(0)}),
Matcher::op_with_rest(GenericOpMatcher::func(Matcher::constant_token("pad-buttons")), {})});
auto static const cpad_matcher_inv = Matcher::op(
GenericOpMatcher::fixed(FixedOperatorKind::LOGTEST),
{Matcher::op_with_rest(GenericOpMatcher::func(Matcher::constant_token("pad-buttons")), {}),
Matcher::deref(Matcher::symbol("*cpad-list*"), false,
{DerefTokenMatcher::string("cpads"), DerefTokenMatcher::any_expr_or_int(0),
DerefTokenMatcher::any_string(2), DerefTokenMatcher::integer(0)})});

bool inv_match = false;
auto mr = match(cpad_matcher, in);
if (!mr.matched) {
mr = match(cpad_matcher_inv, in);
inv_match = true;
}
if (mr.matched) {
enum { ABS, REL, NIL } t = NIL;
if (mr.maps.strings.at(2) == "button0-abs") {
Expand All @@ -4761,8 +4773,8 @@ FormElement* try_make_logtest_cpad_macro(Form* in, FormPool& pool) {

if (t != NIL) {
auto logtest_elt = dynamic_cast<GenericElement*>(in->at(0));
if (logtest_elt != nullptr) {
auto buttons_form = logtest_elt->elts().at(1);
if (logtest_elt) {
auto buttons_form = logtest_elt->elts().at(inv_match ? 0 : 1);
std::vector<Form*> v;
v.push_back(mr.int_or_form_to_form(pool, 0));
GenericElement* butts =
Expand Down Expand Up @@ -4916,7 +4928,14 @@ FormElement* ConditionElement::make_equal_check_generic(const Env& env,
return pool.alloc_element<GenericElement>(GenericOperator::make_fixed(FixedOperatorKind::EQ),
forms_with_cast);
} else {
{
nice_constant =
try_make_constant_for_compare(source_forms.at(0), source_types.at(1), pool, env);
if (nice_constant) {
auto forms_with_cast = source_forms;
forms_with_cast.at(0) = nice_constant;
return pool.alloc_element<GenericElement>(
GenericOperator::make_fixed(FixedOperatorKind::EQ), forms_with_cast);
} else {
// (= (ja-group)
// (-> self draw art-group data 7)
// )
Expand Down
8 changes: 4 additions & 4 deletions decompiler/config/jak2/all-types.gc
Expand Up @@ -3456,13 +3456,13 @@
(x 14)
(square 15)
;; only 16 buttons are mapped to hardware, the rest are 'actions' or something else
(l-analog-down 16)
(l-analog-up 16)
(l-analog-right 17)
(l-analog-up 18)
(l-analog-down 18)
(l-analog-left 19)
(r-analog-down 20)
(r-analog-up 20)
(r-analog-right 21)
(r-analog-up 22)
(r-analog-down 22)
(r-analog-left 23)
(confirm 24)
)
Expand Down
8 changes: 2 additions & 6 deletions goal_src/jak2/engine/game/task/task-control.gc
Expand Up @@ -1649,9 +1649,7 @@
(when (or (and (logtest? (-> self flags) (fail-mission-flags famflags-0))
(>= (- (current-time) (-> self grabbed-time)) (the-as time-frame (-> self reset-delay)))
)
(or (logtest? (pad-buttons confirm) (-> *cpad-list* cpads 0 button0-rel 0))
(logtest? (-> self flags) (fail-mission-flags famflags-3))
)
(or (cpad-pressed? 0 confirm) (logtest? (-> self flags) (fail-mission-flags famflags-3)))
)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
(logclear! (-> *cpad-list* cpads 0 button0-rel 0) (pad-buttons confirm))
Expand All @@ -1665,9 +1663,7 @@
)
(((fail-mission-message fammsg-1))
(until #f
(when (or (logtest? (pad-buttons confirm) (-> *cpad-list* cpads 0 button0-rel 0))
(logtest? (-> self flags) (fail-mission-flags famflags-3))
)
(when (or (cpad-pressed? 0 confirm) (logtest? (-> self flags) (fail-mission-flags famflags-3)))
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
(logclear! (-> *cpad-list* cpads 0 button0-rel 0) (pad-buttons confirm))
(set! (-> self retry) #t)
Expand Down
18 changes: 9 additions & 9 deletions goal_src/jak2/engine/ps2/pad.gc
Expand Up @@ -38,13 +38,13 @@ The cpad-set-buzz! function can be used for vibration.
(x 14)
(square 15)
;; only 16 buttons are mapped to hardware, the rest are 'actions' or something else
(l-analog-down 16)
(l-analog-up 16)
(l-analog-right 17)
(l-analog-up 18)
(l-analog-down 18)
(l-analog-left 19)
(r-analog-down 20)
(r-analog-up 20)
(r-analog-right 21)
(r-analog-up 22)
(r-analog-down 22)
(r-analog-left 23)
(confirm 24)
)
Expand Down Expand Up @@ -284,7 +284,7 @@ The cpad-set-buzz! function can be used for vibration.
(cpad-get-data pad)
(adjust-to-screen-flip pad)
(cond
((zero? (logand (-> pad valid) 128))
((not (logtest? (-> pad valid) 128))
(dotimes (buzz-i 2)
(cond
((and (-> pad buzz) (< (get-current-time) (-> pad buzz-time buzz-i)) (= *master-mode* 'game))
Expand Down Expand Up @@ -402,10 +402,10 @@ The cpad-set-buzz! function can be used for vibration.
(let ((buttons-pushed (the-as pad-buttons (-> pad button0))))
(cond
((< (-> pad lefty) (the-as uint 30))
(set! buttons-pushed (logior (pad-buttons l-analog-down) buttons-pushed))
(set! buttons-pushed (logior (pad-buttons l-analog-up) buttons-pushed))
)
((< (the-as uint 225) (-> pad lefty))
(set! buttons-pushed (logior (pad-buttons l-analog-up) buttons-pushed))
(set! buttons-pushed (logior (pad-buttons l-analog-down) buttons-pushed))
)
)
(cond
Expand All @@ -418,10 +418,10 @@ The cpad-set-buzz! function can be used for vibration.
)
(cond
((< (-> pad righty) (the-as uint 30))
(set! buttons-pushed (logior (pad-buttons r-analog-down) buttons-pushed))
(set! buttons-pushed (logior (pad-buttons r-analog-up) buttons-pushed))
)
((< (the-as uint 225) (-> pad righty))
(set! buttons-pushed (logior (pad-buttons r-analog-up) buttons-pushed))
(set! buttons-pushed (logior (pad-buttons r-analog-down) buttons-pushed))
)
)
(cond
Expand Down
9 changes: 7 additions & 2 deletions goal_src/jak2/engine/ui/progress/progress-draw.gc
Expand Up @@ -3558,7 +3558,9 @@
)
)
(cond
((and (= (-> *setting-control* user-default language) (language-enum german)) (= 454 (-> sv-80 text-name)))
((and (= (-> *setting-control* user-default language) (language-enum german))
(= (text-id progress-missions-stadium-board1) (-> sv-80 text-name))
)
(let ((v1-71 arg1))
(set! (-> v1-71 scale) 0.45)
)
Expand Down Expand Up @@ -7223,7 +7225,10 @@
(set! (-> arg1 origin y) (+ -25.0 (-> arg1 origin y)))
(print-menu-text (lookup-text! *common-text* (-> obj name) #f) (-> obj scale) arg1 arg0)
)
((and (= *title* (-> arg0 current-options)) (= 339 (-> obj name)) (memcard-unlocked-secrets? #f))
((and (= *title* (-> arg0 current-options))
(= (text-id progress-root-secrets) (-> obj name))
(memcard-unlocked-secrets? #f)
)
(print-game-text (lookup-text! *common-text* (-> obj name) #f) arg1 #f 44 (bucket-id progress))
)
((!= (-> obj name) (text-id progress-root-secrets))
Expand Down