masagrator/SaltyNX

Spoof Nintendo calls passed references and sdk structs

Closed this issue · 7 comments

How do you handle these cases? All the examples are passed integers or return integers, I haven't seen any examples dealing with struct pointers or references.

Reference example you have here with TryPopNotificationMessage

https://github.com/masagrator/ReverseNX-RT/blob/master/Plugin/source/main.cpp

I don't have any example with structs. I was planning to use it with UnityGraphics plugin, but after checking that Pokemon in handheld mode returned only 1280, 720, 60 I have dumped this idea as useless.

Ok, nvm about what I wrote about structs earlier.

Here is an example with structs made by SaltyNX author

https://github.com/shinyquagsire23/SaltyNX/blob/master/saltysd_plugin_example/source/main.c

The ghidra decomp of the functions I'm spoofing, that's how I'm getting my function signatures for the most part, have converted all references (all of them are const references in this case) into pointers. Should I change it back to a reference? Example, of 20 functions:

/* nn::hid::GetSixAxisSensorFusionParameters(float*, float*, nn::hid::SixAxisSensorHandle const&) */
void GetSixAxisSensorFusionParameters(float* param_1, float* param_2, nn::hid::SixAxisSensorHandle* handle) {
	if(dumpDebugInfo) {
		SaltySD_printf("SwiTAS_MotionPlugin: GetSixAxisSensorFusionParameters called\n");
	}
	_ZN2nn3hid32GetSixAxisSensorFusionParametersEPfS1_RKNS0_19SixAxisSensorHandleE(param_1, param_2, handle);
}

And this is the kind of example code I use with struct pointers, I hope to be able to modify the struct. I looked at the code you provided, but it almost seemed like it was stockpiling the struct pointers it was reciving, I couldn't tell if it was modifying them at some point.

/* nn::hid::GetSixAxisSensorState(nn::hid::SixAxisSensorState*, nn::hid::SixAxisSensorHandle const&)
 */
void GetSixAxisSensorState(nn::hid::SixAxisSensorState* param_1, nn::hid::SixAxisSensorHandle* param_2) {
	if(dumpDebugInfo) {
		SaltySD_printf("SwiTAS_MotionPlugin: GetSixAxisSensorState called\n");
	}
	_ZN2nn3hid21GetSixAxisSensorStateEPNS0_18SixAxisSensorStateERKNS0_19SixAxisSensorHandleE(param_1, param_2);
}

Plugins can't write and read files from sdcard when game starts booting after Core is killed, that's why SaltySD_printf is useless in this case.
I'm waiting for Atmosphere and xortroll to finish LogManager sysmodule that will allow writing logs to sdcard when game is running.

Atmosphere-NX/Atmosphere#933

Or modify npdm and use sdk functions to read/write sdcard files (which I can't help as I never used sdk for it)

For floats* definitely you should use references.
For structures I don't think you need to use it, but I'm not sure.

Is there a way I could ask more small questions on discord? I just want to get to know the system.

MasaGratoR#1567