fivem icon indicating copy to clipboard operation
fivem copied to clipboard

tweak(natives/rpc): Use client-native names and apply aliases

Open tens0rfl0w opened this issue 1 year ago • 8 comments

Goal of this PR

Commit https://github.com/citizenfx/natives/commit/e6f473573f6eb7e2921b2ef48668117cbbe84bbb changed the native name from '_SET_PED_HAIR_COLOR' to 'SET_PED_HAIR_TINT' which makes the RPC native definition invalid.

How is this PR achieving the goal

We now also check for alias matches when generating RPC decl. in codegen and apply client-native aliases to RPC natives. This allows us to keep RPC native naming in sync with client-native changes while maintaining backward compatibility with old native naming (like on the client side).

This PR applies to the following area(s)

FiveM, Natives (RPC)

Successfully tested on

Game builds: 2699

Platforms: Windows

Checklist

  • [x] Code compiles and has been tested successfully.
  • [x] Code explains itself well and/or is documented.
  • [x] My commit message explains what the changes do and what they are for.
  • [x] No extra compilation warnings are added by these changes.

Fixes issues

fixes #2549 fixes #2447 fixes https://forum.cfx.re/t/5226975

tens0rfl0w avatar May 18 '24 17:05 tens0rfl0w

Why some functions names start with _?

DaniGP17 avatar May 18 '24 21:05 DaniGP17

Names that start with underscore mean that the native name isn't known.

AvarianKnight avatar May 18 '24 21:05 AvarianKnight

maybe CALL_MINIMAP_SCALEFORM_FUNCTION can also be renamed to BEGIN_SCALEFORM_MOVIE_METHOD_ON_MINIMAP?

freedy69 avatar May 18 '24 23:05 freedy69

maybe CALL_MINIMAP_SCALEFORM_FUNCTION can also be renamed to BEGIN_SCALEFORM_MOVIE_METHOD_ON_MINIMAP?

Why should this native be renamed? This is a custom native, not a base-game native.

Also, PRs are generally not the best place to suggest other stuff as this PR is about RPC natives.

tens0rfl0w avatar May 18 '24 23:05 tens0rfl0w

maybe CALL_MINIMAP_SCALEFORM_FUNCTION can also be renamed to BEGIN_SCALEFORM_MOVIE_METHOD_ON_MINIMAP?

Why should this native be renamed? This is a custom native, not a base-game native.

Also, PRs are generally not the best place to suggest other stuff as this PR is about RPC natives.

Im just saying because it would fit naming formatting of other scaleform natives. Would make more sense, im not really suggesting, more so pointing out since this is about renaming a native

freedy69 avatar May 19 '24 00:05 freedy69

This PR is not about renaming a native. The natives name was already changed months ago. This just aims to fix the RPC native naming, so it can be invoked from the server-side again.

tens0rfl0w avatar May 19 '24 01:05 tens0rfl0w

To avoid breaking compatibility here, it should be safe (i.e., requires testing) to update getNative to also search through aliases, e.g.,

local function getNative(nativeName)
	-- get the native
	for k, v in ipairs(natives) do
		if #v.apiset == 0 or v.apiset[1] == 'client' then
			if v.name == nativeName then
				return v
			end

			for _,aliasName in ipairs(v.aliases) do
				if nativeName == aliasName then
					return v
				end
			end
		end
	end
	return nil
end

Updating this script to use a reverse name lookup would probably be better. That can be done later though.

gottfriedleibniz avatar May 19 '24 01:05 gottfriedleibniz

@gottfriedleibniz Tested your provided snippet. Works to keep backwards compatibility for old native naming. I also applied client aliases to RPC natives and used the 'real' client-native naming to keep RPC natives in sync while keeping backwards compatibility.

Couldn't find any regressions when testing this change, but not sure.

(Those code styling fixes can be removed if unwanted)

tens0rfl0w avatar May 19 '24 13:05 tens0rfl0w