mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
Every RegisterFrameMethods call passed its method table and doc table with a count beside each: sizeof(t) / sizeof(t[0]), std::size, or a literal. The literals had to be kept in step with the tables by hand. Game::ArrayRef<T> is a view over a file-scope array that takes the count from the array's type, the way Doc::FieldList already did for a function's arguments and returns. FieldList is now ArrayRef<Field>, Doc::MethodList is ArrayRef<Method>, and RegisterFrameMethods takes (context, methods, docs). The table and count still go to the engine's frame-method iterator (FUN_REGISTER_FRAME_METHODS) unchanged, and to the documentation recorder. All 84 call sites pass only the arrays. The 16 literal counts were checked against their tables first: each was the full length, so every registry gets the same methods as before.
72 lines
2.8 KiB
C++
72 lines
2.8 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI 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.
|
|
//
|
|
// ClassicAPI 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
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// `PlayerModel:SetRotation(rotation [, animate])` — 4.3.4's second argument.
|
|
//
|
|
// Vanilla's SetRotation (FUN_SCRIPT_PLAYERMODEL_SET_ROTATION) always turns the
|
|
// model with a shuffle animation (TurnTo 0x00505BB0). 4.3.4's RotateModel
|
|
// (CharacterModelBase.cpp) does the same when `animate` is true or absent, and
|
|
// with `animate` false only stores the facing: no shuffle, no turn latch. It
|
|
// also only stores the facing while the pane rests on an animation other than
|
|
// Stand (`m_sequence`, set by SetAnimation, see Model::Animation). Otherwise
|
|
// vanilla's method runs unchanged.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "model/Animation.h"
|
|
|
|
namespace Model::Rotation {
|
|
namespace {
|
|
|
|
int __fastcall Script_SetRotation(void *L) {
|
|
void *pane = Game::Lua::ResolvePlayerModel(L);
|
|
if (pane == nullptr)
|
|
return 0;
|
|
const bool animate =
|
|
Game::Lua::Type(L, 3) == Game::Lua::TYPE_NONE || Game::Lua::ToBoolean(L, 3) != 0;
|
|
if (animate && !Model::Animation::HasRestingAnimation(pane))
|
|
return reinterpret_cast<Game::Lua::CFunction>(
|
|
Offsets::FUN_SCRIPT_PLAYERMODEL_SET_ROTATION)(L);
|
|
if (!Game::Lua::IsNumber(L, 2)) {
|
|
Game::Lua::Error(L, "Usage: SetRotation(rotation (in radians))");
|
|
return 0;
|
|
}
|
|
Game::Ref<float>(pane, Offsets::OFF_SIMPLEMODEL_FACING) =
|
|
static_cast<float>(Game::Lua::ToNumber(L, 2));
|
|
return 0;
|
|
}
|
|
|
|
const Game::Lua::FrameMethodEntry g_methods[] = {
|
|
{"SetRotation", &Script_SetRotation},
|
|
};
|
|
|
|
const Game::Doc::Field kArgs[] = {
|
|
Game::Doc::Req("rotation", "number", "The facing in radians."),
|
|
Game::Doc::Opt("animate", "bool", "true", "False turns the model without the shuffle animation."),
|
|
};
|
|
const Game::Doc::Function kSetRotation{"Turns the model to a facing.", kArgs, {}};
|
|
const Game::Doc::Method g_methodDocs[] = {
|
|
{"SetRotation", &kSetRotation},
|
|
};
|
|
|
|
void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterFrameMethods(
|
|
reinterpret_cast<void *>(Offsets::VAR_PLAYERMODEL_METHOD_REGISTRY), g_methods,
|
|
g_methodDocs);
|
|
}
|
|
|
|
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace
|
|
} // namespace Model::Rotation
|