change some reinterpret_casts to static_casts

This commit is contained in:
altalk23 2022-10-22 20:19:58 +03:00
parent cb9d6f212a
commit a88e69fb0c
16 changed files with 46 additions and 49 deletions

View file

@ -1020,7 +1020,7 @@ class EditButtonBar : cocos2d::CCNode {
}
void addButton(CCMenuItemSpriteExtra* btn, bool reload) {
if (this->m_buttonArray)
this->m_buttonArray->addObject(reinterpret_cast<cocos2d::CCObject*>(btn));
this->m_buttonArray->addObject(static_cast<cocos2d::CCObject*>(btn));
if (reload)
this->reloadItemsInNormalSize();
}
@ -1039,7 +1039,7 @@ class EditLevelLayer : cocos2d::CCLayer, FLAlertLayerProtocol, TextInputDelegate
static void scene(GJGameLevel* level) {
auto scene = cocos2d::CCScene::create();
scene->addChild(reinterpret_cast<cocos2d::CCNode*>(EditLevelLayer::create(level)));
scene->addChild(static_cast<cocos2d::CCNode*>(EditLevelLayer::create(level)));
cocos2d::CCDirector::sharedDirector()->replaceScene(
cocos2d::CCTransitionFade::create(.5f, scene)
@ -1305,7 +1305,7 @@ class EditorUI : cocos2d::CCLayer, FLAlertLayerProtocol, ColorSelectDelegate, GJ
class EffectGameObject : GameObject {
void updateLabel() {
auto label = reinterpret_cast<cocos2d::CCLabelBMFont*>(this->getChildByTag(999));
auto label = static_cast<cocos2d::CCLabelBMFont*>(this->getChildByTag(999));
if (label) {
switch (this->m_objectID) {
// instant count, collision block, pickup
@ -2748,13 +2748,13 @@ class GameManager : GManager {
return m_levelEditorLayer;
}
bool getGameVariableDefault(const char* key, bool defaultValue) {
auto object = reinterpret_cast<cocos2d::CCString*>(m_valueKeeper->objectForKey(std::string("gv_") + key));
auto object = static_cast<cocos2d::CCString*>(m_valueKeeper->objectForKey(std::string("gv_") + key));
if (object == nullptr)
return defaultValue;
return object->boolValue();
}
int getIntGameVariableDefault(const char* key, int defaultValue) {
auto object = reinterpret_cast<cocos2d::CCString*>(m_valueKeeper->objectForKey(std::string("gv_") + key));
auto object = static_cast<cocos2d::CCString*>(m_valueKeeper->objectForKey(std::string("gv_") + key));
if (object == nullptr)
return defaultValue;
return object->intValue();
@ -4028,10 +4028,10 @@ class ObjectToolbox : cocos2d::CCNode {
return m_frameToKeyDict->allKeys();
}
const char* frameToKey(const char* frame) {
return reinterpret_cast<cocos2d::CCString*>(m_frameToKeyDict->objectForKey(frame))->getCString();
return static_cast<cocos2d::CCString*>(m_frameToKeyDict->objectForKey(frame))->getCString();
}
const char* intKeyToFrame(int key) {
return reinterpret_cast<cocos2d::CCString*>(m_keyToFrameDict->objectForKey(key))->getCString();
return static_cast<cocos2d::CCString*>(m_keyToFrameDict->objectForKey(key))->getCString();
}
const char* keyToFrame(const char* key) {
return intKeyToFrame(atoi(key));

View file

@ -22,6 +22,7 @@ namespace { namespace format_strings {
char const* class_start = R"GEN(
class {class_name}{base_classes} {{
public:
static constexpr auto CLASS_NAME = "{class_name}";
)GEN";
char const* monostate_constructor = R"GEN( GEODE_MONOSTATE_CONSTRUCTOR_GD({class_name}, {first_base})

View file

@ -558,11 +558,6 @@ namespace geode {
*/
std::vector<Dependency> getUnresolvedDependencies();
template<class T>
T* with() {
return reinterpret_cast<T*>(this);
}
const char* expandSpriteName(const char* name);
};

View file

@ -77,12 +77,6 @@ struct GEODE_HIDDEN derived : derived##Intermediate
*/
#define $cls std::remove_pointer<decltype(this)>::type
#define GEODE_ONLY_FIELD(type, field_, default_) private: field<type> field_ = default_; public:
#define GEODE_INTERNAL_FIELD(type, field, name) inline type& name() { return this->*field; }
//#define GEODE_EXTERNAL_FIELD(type, field, name) static inline type& name##From(void* self) { return reinterpret_cast<decltype(this)>(self)->*field; }
#define GEODE_FIELD(type, field, name, default_) GEODE_ONLY_FIELD(type, field, default_) GEODE_INTERNAL_FIELD(type, field, name) //GEODE_EXTERNAL_FIELD(type, field, name)
#define GEODE_EXECUTE_FUNC(Line_) \
template<class> \
void _##Line_##Function(); \

View file

@ -7,11 +7,11 @@
namespace geode::cast {
/**
* Alias for reinterpret_cast
* Alias for static_cast
*/
template <typename T, typename F>
static constexpr T as(F const v) {
return reinterpret_cast<T>(v);
return static_cast<T>(v);
}
/**

View file

@ -21,7 +21,7 @@ namespace geode::cocos {
if (i < 0) return nullptr;
// check if forwards index is out of bounds
if (static_cast<int>(x->getChildrenCount()) <= i) return nullptr;
return reinterpret_cast<T*>(x->getChildren()->objectAtIndex(i));
return static_cast<T*>(x->getChildren()->objectAtIndex(i));
}
/**
@ -306,7 +306,7 @@ namespace geode::cocos {
return m_arr->count();
}
T operator[](size_t index) {
return reinterpret_cast<T*>(m_arr->objectAtIndex(index));
return static_cast<T*>(m_arr->objectAtIndex(index));
}
void push_back(T* item) {
m_arr->addObject(item);
@ -329,14 +329,14 @@ namespace geode::cocos {
std::pair<K, T> operator*() {
if constexpr (std::is_same<K, std::string>::value) {
return { m_ptr->getStrKey(), reinterpret_cast<T>(m_ptr->getObject()) };
return { m_ptr->getStrKey(), static_cast<T>(m_ptr->getObject()) };
} else {
return { m_ptr->getIntKey(), reinterpret_cast<T>(m_ptr->getObject()) };
return { m_ptr->getIntKey(), static_cast<T>(m_ptr->getObject()) };
}
}
auto& operator++() {
m_ptr = reinterpret_cast<decltype(m_ptr)>(m_ptr->hh.next);
m_ptr = static_cast<decltype(m_ptr)>(m_ptr->hh.next);
return *this;
}
@ -353,11 +353,11 @@ namespace geode::cocos {
CCDictEntry(K key, cocos2d::CCDictionary* dict) : m_key(key), m_dict(dict) {}
T operator->() {
return reinterpret_cast<T>(m_dict->objectForKey(m_key));
return static_cast<T>(m_dict->objectForKey(m_key));
}
operator T() {
return reinterpret_cast<T>(m_dict->objectForKey(m_key));
return static_cast<T>(m_dict->objectForKey(m_key));
}
CCDictEntry& operator=(T f) {
@ -404,7 +404,7 @@ namespace geode::cocos {
}
size_t size() { return m_dict->count(); }
auto operator[](K key) {
auto ret = reinterpret_cast<T*>(m_dict->objectForKey(key));
auto ret = static_cast<T*>(m_dict->objectForKey(key));
if (!ret)
m_dict->setObject(cocos2d::CCNode::create(), key);

View file

@ -110,6 +110,16 @@ class $modify(CustomMenuLayer, MenuLayer) {
setIDSafe<CCLabelBMFont>(this, 2, "player-username");
} else {
setIDSafe<CCLabelBMFont>(this, 0, "player-username");
auto spriteId = 1;
if (!GameManager::get()->m_clickedGarage) {
setIDSafe<CCSprite>(this, spriteId++, "click-garage-message");
}
if (!GameManager::get()->m_clickedEditor) {
setIDSafe<CCSprite>(this, spriteId++, "click-editor-message");
}
}
if (auto menu = getChildOfType<CCMenu>(this, 0)) {
menu->setID("main-menu");

View file

@ -15,7 +15,6 @@ class $modify(CCUtility##HandlerTypeinfoFix, CCUtility##Handler) {
if (pObject) { \
pObject->release(); \
} \
/*reinterpret_cast<CCObject*>(this)->~CCObject();*/ \
} \
} \
\
@ -63,7 +62,6 @@ class $modify(CCTargetedTouchHandlerTypeinfoFix, CCTargetedTouchHandler) {
pObject->release();
CC_SAFE_RELEASE(m_pClaimedTouches);
}
/*reinterpret_cast<CCObject*>(this)->~CCObject();*/
}
}
@ -109,7 +107,6 @@ class $modify(CCStandardTouchHandlerTypeinfoFix, CCStandardTouchHandler) {
// the entire destructor
pObject->release();
}
/*reinterpret_cast<CCObject*>(this)->~CCObject();*/
}
}

View file

@ -33,7 +33,7 @@ void FileWatcher::watch() {
DISPATCH_VNODE_ATTRIB | DISPATCH_VNODE_LINK | DISPATCH_VNODE_RENAME |
DISPATCH_VNODE_REVOKE, queue);
this->m_platform_handle = reinterpret_cast<void*>(source);
this->m_platform_handle = static_cast<void*>(source);
dispatch_source_set_event_handler(source, ^{
if (this->m_callback) {

View file

@ -33,7 +33,7 @@ void FileWatcher::watch() {
DISPATCH_VNODE_ATTRIB | DISPATCH_VNODE_LINK | DISPATCH_VNODE_RENAME |
DISPATCH_VNODE_REVOKE, queue);
this->m_platform_handle = reinterpret_cast<void*>(source);
this->m_platform_handle = static_cast<void*>(source);
dispatch_source_set_event_handler(source, ^{
if (this->m_callback) {

View file

@ -185,7 +185,7 @@ static void walkStack(std::ostream& stream, PCONTEXT context) {
)) break;
stream << " - ";
printAddr(stream, reinterpret_cast<void*>(stack.AddrPC.Offset));
printAddr(stream, static_cast<void*>(stack.AddrPC.Offset));
stream << std::endl;
}
}

View file

@ -38,7 +38,7 @@ Result<> Mod::enableHook(Hook* hook) {
return Ok<>();
} else {
return Err<>(
"Unable to create hook at " + std::to_string(as<uintptr_t>(hook->m_address))
"Unable to create hook at " + std::to_string(reinterpret_cast<uintptr_t>(hook->m_address))
);
}
return Err<>("Hook already has a handle");

View file

@ -14,7 +14,7 @@ USE_GEODE_NAMESPACE();
byte_array readMemory(void* address, size_t amount) {
byte_array ret;
for (size_t i = 0; i < amount; i++) {
ret.push_back(*as<uint8_t*>(as<uintptr_t>(address) + i));
ret.push_back(*reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(address) + i));
}
return ret;
}

View file

@ -7,12 +7,12 @@ USE_GEODE_NAMESPACE();
std::string g_lastError = "";
void geode_mod_log(void* cmod, const char* message) {
auto mod = reinterpret_cast<Mod*>(cmod);
auto mod = static_cast<Mod*>(cmod);
log::log(Severity::Debug, mod, "{}", message);
}
bool geode_mod_add_hook(void* cmod, void* address, void* detour) {
// auto mod = reinterpret_cast<Mod*>(cmod);
// auto mod = static_cast<Mod*>(cmod);
// auto res = mod->addHook(address, detour);
// if (!res) {
// g_lastError = res.error();

View file

@ -220,7 +220,7 @@ struct MDParser {
static std::vector<TextRenderer::Label> s_codeSpans;
static int parseText(MD_TEXTTYPE type, MD_CHAR const* rawText, MD_SIZE size, void* mdtextarea) {
auto textarea = reinterpret_cast<MDTextArea*>(mdtextarea);
auto textarea = static_cast<MDTextArea*>(mdtextarea);
auto renderer = textarea->m_renderer;
auto text = std::string(rawText, size);
switch (type) {
@ -316,13 +316,13 @@ struct MDParser {
}
static int enterBlock(MD_BLOCKTYPE type, void* detail, void* mdtextarea) {
auto textarea = reinterpret_cast<MDTextArea*>(mdtextarea);
auto textarea = static_cast<MDTextArea*>(mdtextarea);
auto renderer = textarea->m_renderer;
switch (type) {
case MD_BLOCKTYPE::MD_BLOCK_DOC: {} break;
case MD_BLOCKTYPE::MD_BLOCK_H: {
auto hdetail = reinterpret_cast<MD_BLOCK_H_DETAIL*>(detail);
auto hdetail = static_cast<MD_BLOCK_H_DETAIL*>(detail);
renderer->pushStyleFlags(TextStyleBold);
switch (hdetail->level) {
case 1: renderer->pushScale(g_fontScale * 2.f); break;
@ -355,7 +355,7 @@ struct MDParser {
case MD_BLOCKTYPE::MD_BLOCK_LI: {
renderer->pushOpacity(renderer->getCurrentOpacity() / 2);
auto lidetail = reinterpret_cast<MD_BLOCK_LI_DETAIL*>(detail);
auto lidetail = static_cast<MD_BLOCK_LI_DETAIL*>(detail);
if (s_isOrderedList) {
s_orderedListNum++;
renderer->renderString(std::to_string(s_orderedListNum) + ". ");
@ -381,13 +381,13 @@ struct MDParser {
}
static int leaveBlock(MD_BLOCKTYPE type, void* detail, void* mdtextarea) {
auto textarea = reinterpret_cast<MDTextArea*>(mdtextarea);
auto textarea = static_cast<MDTextArea*>(mdtextarea);
auto renderer = textarea->m_renderer;
switch (type) {
case MD_BLOCKTYPE::MD_BLOCK_DOC: {} break;
case MD_BLOCKTYPE::MD_BLOCK_H: {
auto hdetail = reinterpret_cast<MD_BLOCK_H_DETAIL*>(detail);
auto hdetail = static_cast<MD_BLOCK_H_DETAIL*>(detail);
renderer->breakLine();
if (hdetail->level == 1) {
renderer->breakLine(g_paragraphPadding / 2);
@ -463,7 +463,7 @@ struct MDParser {
}
static int enterSpan(MD_SPANTYPE type, void* detail, void* mdtextarea) {
auto renderer = reinterpret_cast<MDTextArea*>(mdtextarea)->m_renderer;
auto renderer = static_cast<MDTextArea*>(mdtextarea)->m_renderer;
switch (type) {
case MD_SPANTYPE::MD_SPAN_STRONG: {
renderer->pushStyleFlags(TextStyleBold);
@ -482,12 +482,12 @@ struct MDParser {
} break;
case MD_SPANTYPE::MD_SPAN_IMG: {
auto adetail = reinterpret_cast<MD_SPAN_IMG_DETAIL*>(detail);
auto adetail = static_cast<MD_SPAN_IMG_DETAIL*>(detail);
s_lastImage = std::string(adetail->src.text, adetail->src.size);
} break;
case MD_SPANTYPE::MD_SPAN_A: {
auto adetail = reinterpret_cast<MD_SPAN_A_DETAIL*>(detail);
auto adetail = static_cast<MD_SPAN_A_DETAIL*>(detail);
s_lastLink = std::string(adetail->href.text, adetail->href.size);
} break;
@ -504,7 +504,7 @@ struct MDParser {
}
static int leaveSpan(MD_SPANTYPE type, void* detail, void* mdtextarea) {
auto renderer = reinterpret_cast<MDTextArea*>(mdtextarea)->m_renderer;
auto renderer = static_cast<MDTextArea*>(mdtextarea)->m_renderer;
switch (type) {
case MD_SPANTYPE::MD_SPAN_STRONG: {
renderer->popStyleFlags();

View file

@ -197,7 +197,7 @@ SentAsyncWebRequest::SentAsyncWebRequest(
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION,
+[](void* ptr, double total, double now, double, double) -> int {
auto data = reinterpret_cast<ProgressData*>(ptr);
auto data = static_cast<ProgressData*>(ptr);
while (data->self->m_paused) {}
if (data->self->m_cancelled) {
if (data->file) {