Browse Source

Rename local variable to avoid conflicts

pull/14/head
Anton Tarasenko 2 years ago
parent
commit
8a6891793f
  1. 3
      sources/BaseAPI/API/Commands/BuiltInCommands/ACommandNotify.uc
  2. 1
      sources/BaseAPI/API/Unflect/UnflectApi.uc
  3. 100
      sources/Chat/ChatAPI.uc
  4. 8
      sources/Players/EPlayer.uc

3
sources/BaseAPI/API/Commands/BuiltInCommands/ACommandNotify.uc

@ -19,7 +19,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>. * along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/ */
class ACommandNotify extends Command; class ACommandNotify extends Command
dependsOn(ChatApi);
protected function BuildData(CommandDataBuilder builder) { protected function BuildData(CommandDataBuilder builder) {
builder.Name(P("notify")); builder.Name(P("notify"));

1
sources/BaseAPI/API/Unflect/UnflectApi.uc

@ -306,6 +306,7 @@ private final function bool _replaceFunction(Text oldFunctionLowerCase, Text new
_.memory.Free(initialCode); _.memory.Free(initialCode);
} }
replace.script = with.script; replace.script = with.script;
Log("TRULLY!" @ replace @ with);
return true; return true;
} }

100
sources/Chat/ChatAPI.uc

@ -21,14 +21,19 @@
*/ */
class ChatApi extends AcediaObject; class ChatApi extends AcediaObject;
var private const int VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS; ///! API for accessing chat-related events.
var private const int VOICE_MESSAGES_BEFORE_ALERTS; ///!
var private const int VOICE_MESSAGES_BEFORE_DIRECTIONS; ///! # Implementation
var private const int VOICE_MESSAGES_BEFORE_INSULTS; ///!
var private const int VOICE_MESSAGES_BEFORE_TRADER; ///! Signal functions that track text chat messages `OnMessage()` and `OnMessageFor()` simply
var private const int VOICE_MESSAGES_BEFORE_AUTO; ///! hook into [`BroadcastApi`] the first time such signal is requested.
var private const int VOICE_MESSAGES_TOTAL; ///!
///! Signal function [`OnVoiceMessage()`] for tracking voice replaces a function in
///! [`KFPlayerController`] to track when they are replicated.
///! Then replaced function informs [`ChatApi`] about new voice message transmissions via
///! internal [`_EmitOnVoiceMessage()`] method.
/// Lists voice messages built-in in the game.
enum BuiltInVoiceMessage { enum BuiltInVoiceMessage {
// Support // Support
BIVM_SupportMedic, BIVM_SupportMedic,
@ -98,41 +103,53 @@ enum BuiltInVoiceMessage {
BIVM_Unknown BIVM_Unknown
}; };
/// Killing Floor's native voice message is defined by `name` and `byte` pair.
/// This struct is added to allow returning them as a pair.
struct NativeVoiceMessage { struct NativeVoiceMessage {
var name type; var name type;
var byte index; var byte index;
}; };
/// Tracks whether we've already connected to broadcast signals.
var protected bool connectedToBroadcastAPI; var protected bool connectedToBroadcastAPI;
/// Tracks whether we've already replaced a function that allows us to catch voice messages.
var private bool replacedSendVoiceMessage;
/// Auxiliary constants that store amount of values in [`BuiltInVoiceMessage`] before
/// a certain group.
/// Used for conversion between native voice messages and [`BuiltInVoiceMessage`]
var private const int VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS;
var private const int VOICE_MESSAGES_BEFORE_ALERTS;
var private const int VOICE_MESSAGES_BEFORE_DIRECTIONS;
var private const int VOICE_MESSAGES_BEFORE_INSULTS;
var private const int VOICE_MESSAGES_BEFORE_TRADER;
var private const int VOICE_MESSAGES_BEFORE_AUTO;
var private const int VOICE_MESSAGES_TOTAL;
var protected ChatAPI_OnMessage_Signal onMessageSignal; var protected ChatAPI_OnMessage_Signal onMessageSignal;
var protected ChatAPI_OnMessageFor_Signal onMessageForSignal; var protected ChatAPI_OnMessageFor_Signal onMessageForSignal;
var protected ChatAPI_OnVoiceMessage_Signal onVoiceMessageSignal;
protected function Constructor() { protected function Constructor() {
onMessageSignal = ChatAPI_OnMessage_Signal(_.memory.Allocate(class'ChatAPI_OnMessage_Signal')); onMessageSignal = ChatAPI_OnMessage_Signal(_.memory.Allocate(class'ChatAPI_OnMessage_Signal'));
onMessageForSignal = onMessageForSignal =
ChatAPI_OnMessageFor_Signal(_.memory.Allocate(class'ChatAPI_OnMessageFor_Signal')); ChatAPI_OnMessageFor_Signal(_.memory.Allocate(class'ChatAPI_OnMessageFor_Signal'));
onVoiceMessageSignal =
ChatAPI_OnVoiceMessage_Signal(_.memory.Allocate(class'ChatAPI_OnVoiceMessage_Signal'));
} }
protected function Finalizer() { protected function Finalizer() {
_.memory.Free(onMessageSignal); _.memory.Free(onMessageSignal);
_.memory.Free(onMessageForSignal); _.memory.Free(onMessageForSignal);
_.memory.Free(onVoiceMessageSignal);
onMessageSignal = none; onMessageSignal = none;
onMessageForSignal = none; onMessageForSignal = none;
onVoiceMessageSignal = none;
_server.unreal.broadcasts.OnHandleText(self).Disconnect(); _server.unreal.broadcasts.OnHandleText(self).Disconnect();
_server.unreal.broadcasts.OnHandleTextFor(self).Disconnect(); _server.unreal.broadcasts.OnHandleTextFor(self).Disconnect();
connectedToBroadcastAPI = false; connectedToBroadcastAPI = false;
} }
private final function TryConnectingBroadcastSignals() {
if (connectedToBroadcastAPI) {
return;
}
connectedToBroadcastAPI = true;
_server.unreal.broadcasts.OnHandleText(self).connect = HandleText;
_server.unreal.broadcasts.OnHandleTextFor(self).connect = HandleTextFor;
}
/// Signal that will be emitted when a player sends a message into the chat. /// Signal that will be emitted when a player sends a message into the chat.
/// ///
/// Allows to modify message before sending it, as well as prevent it from being sent at all. /// Allows to modify message before sending it, as well as prevent it from being sent at all.
@ -189,6 +206,27 @@ public /*signal*/ function ChatAPI_OnMessageFor_Slot OnMessageFor(AcediaObject r
return ChatAPI_OnMessageFor_Slot(onMessageForSignal.NewSlot(receiver)); return ChatAPI_OnMessageFor_Slot(onMessageForSignal.NewSlot(receiver));
} }
/// Signal that will be emitted when a player sends a voice message.
///
/// # Slot description
///
/// bool <slot>(EPlayer sender, ChatApi.BuiltInVoiceMessage message)
///
/// ## Parameters
///
/// * [`sender`]: `EPlayer` that has sent the voice message.
/// * [`message`]: Message that `sender` has sent.
public /*signal*/ function ChatAPI_OnVoiceMessage_Slot OnVoiceMessage(AcediaObject receiver) {
if (!replacedSendVoiceMessage) {
_.unflect.ReplaceFunction_S(
"KFMod.KFPlayerController.SendVoiceMessage",
"AcediaCore.Unflect_ChatApi_Controller.SendVoiceMessage",
"`ChatApi` was required to catch voice messages");
replacedSendVoiceMessage = true;
}
return ChatAPI_OnVoiceMessage_Slot(onVoiceMessageSignal.NewSlot(receiver));
}
public /*internal*/ function NativeVoiceMessage _enumIntoNativeVoiceMessage( public /*internal*/ function NativeVoiceMessage _enumIntoNativeVoiceMessage(
BuiltInVoiceMessage voiceMessage BuiltInVoiceMessage voiceMessage
) { ) {
@ -275,6 +313,36 @@ public /*internal*/ function BuiltInVoiceMessage _nativeVoiceMessageIntoEnum(
return BIVM_Unknown; return BIVM_Unknown;
} }
public final /*internal*/ /*native*/ function _EmitOnVoiceMessage(
PlayerController sender,
name messageType,
byte messageID
) {
local EPlayer wrapper;
local NativeVoiceMessage nativeVoiceMessage;
local BuiltInVoiceMessage builtInVoiceMessage;
if (sender == none) return;
wrapper = _.players.FromController(sender);
if (wrapper == none) return;
nativeVoiceMessage.type = messageType;
nativeVoiceMessage.index = messageID;
builtInVoiceMessage = _nativeVoiceMessageIntoEnum(nativeVoiceMessage);
if (builtInVoiceMessage != BIVM_Unknown) {
onVoiceMessageSignal.Emit(wrapper, builtInVoiceMessage);
}
_.memory.Free(wrapper);
}
private final function TryConnectingBroadcastSignals() {
if (connectedToBroadcastAPI) {
return;
}
connectedToBroadcastAPI = true;
_server.unreal.broadcasts.OnHandleText(self).connect = HandleText;
_server.unreal.broadcasts.OnHandleTextFor(self).connect = HandleTextFor;
}
private function bool HandleText( private function bool HandleText(
Actor sender, Actor sender,

8
sources/Players/EPlayer.uc

@ -507,15 +507,15 @@ public final function /* borrow */ ConsoleWriter BorrowConsole()
/// Sends specified voice message from the caller player to all players in the game. /// Sends specified voice message from the caller player to all players in the game.
public final function SendVoiceMessage(ChatApi.BuiltInVoiceMessage voiceMessage) { public final function SendVoiceMessage(ChatApi.BuiltInVoiceMessage voiceMessage) {
local PlayerController controller; local PlayerController myController;
local ChatApi.NativeVoiceMessage nativeMessage; local ChatApi.NativeVoiceMessage nativeMessage;
if (voiceMessage == BIVM_Unknown) return; if (voiceMessage == BIVM_Unknown) return;
controller = GetController(); myController = GetController();
if (controller == none) return; if (myController == none) return;
nativeMessage = _.chat._enumIntoNativeVoiceMessage(voiceMessage); nativeMessage = _.chat._enumIntoNativeVoiceMessage(voiceMessage);
controller.ServerSpeech(nativeMessage.type, nativeMessage.index, ""); myController.ServerSpeech(nativeMessage.type, nativeMessage.index, "");
} }
/// Sends a text message to notify the player about a particular event or situation, displayed /// Sends a text message to notify the player about a particular event or situation, displayed

Loading…
Cancel
Save