id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
752,068
|
sippresence.h
|
savoirfairelinux_jami-daemon/src/sip/sippresence.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SIPPRESENCE_H
#define SIPPRESENCE_H
#include <string>
#include <list>
#include <mutex>
#include "noncopyable.h"
#include "pjsip/sip_types.h"
#include "pjsip/sip_msg.h"
#include "pjsip/sip_multipart.h"
#include "pjsip-simple/publish.h"
#include "pjsip-simple/presence.h"
#include "pjsip-simple/rpid.h"
#include <pj/pool.h>
#define PRESENCE_FUNCTION_PUBLISH 0
#define PRESENCE_FUNCTION_SUBSCRIBE 1
#define PRESENCE_LOCK_FLAG 1
#define PRESENCE_CLIENT_LOCK_FLAG 2
namespace jami {
struct pres_msg_data
{
/**
* Additional message headers as linked list. Application can add
* headers to the list by creating the header, either from the heap/pool
* or from temporary local variable, and add the header using
* linked list operation. See pjsip_apps.c for some sample codes.
*/
pjsip_hdr hdr_list;
/**
* MIME type of optional message body.
*/
pj_str_t content_type;
/**
* Optional message body to be added to the message, only when the
* message doesn't have a body.
*/
pj_str_t msg_body;
/**
* Content type of the multipart body. If application wants to send
* multipart message bodies, it puts the parts in \a parts and set
* the content type in \a multipart_ctype. If the message already
* contains a body, the body will be added to the multipart bodies.
*/
pjsip_media_type multipart_ctype;
/**
* List of multipart parts. If application wants to send multipart
* message bodies, it puts the parts in \a parts and set the content
* type in \a multipart_ctype. If the message already contains a body,
* the body will be added to the multipart bodies.
*/
pjsip_multipart_part multipart_parts;
};
class SIPAccount;
class PresSubClient;
class PresSubServer;
/**
* @file sippresence.h
* @brief A SIP Presence manages buddy subscription in both PBX and IP2IP contexts.
*/
class SIPPresence
{
public:
/**
* Constructor
* @param acc the associated sipaccount
*/
SIPPresence(SIPAccount* acc);
/**
* Destructor
*/
~SIPPresence();
/**
* Return associated sipaccount
*/
SIPAccount* getAccount() const;
/**
* Return presence data.
*/
pjsip_pres_status* getStatus();
/**
* Return presence module ID which is actually the same as the VOIP link
*/
int getModId() const;
/**
* Return a pool for generic functions.
*/
pj_pool_t* getPool() const;
/**
* Activate the module.
* @param enable Flag
*/
void enable(bool enabled);
/**
* Support the presence function publish/subscribe.
* @param function Publish or subscribe to enable
* @param enable Flag
*/
void support(int function, bool enabled);
/**
* Fill xml document, the header and the body
*/
void fillDoc(pjsip_tx_data* tdata, const pres_msg_data* msg_data);
/**
* Modify the presence data
* @param status is basically "open" or "close"
*/
void updateStatus(bool status, const std::string& note);
/**
* Send the presence data in a PUBLISH to the PBX or in a NOTIFY
* to a remote subscriber (IP2IP)
*/
void sendPresence(bool status, const std::string& note);
/**
* Send a signal to the client on DBus. The signal contain the status
* of a remote user.
*/
void reportPresSubClientNotification(std::string_view uri, pjsip_pres_status* status);
/**
* Send a SUBSCRIBE request to PBX/IP2IP
* @param buddyUri Remote user that we want to subscribe
*/
void subscribeClient(const std::string& uri, bool flag);
/**
* Add a buddy in the buddy list.
* @param b PresSubClient pointer
*/
void addPresSubClient(PresSubClient* b);
/**
* Remove a buddy from the list.
* @param b PresSubClient pointer
*/
void removePresSubClient(PresSubClient* b);
/**
* IP2IP context.
* Process new subscription based on client decision.
* @param flag client decision.
* @param uri uri of the remote subscriber
*/
void approvePresSubServer(const std::string& uri, bool flag);
/**
* IP2IP context.
* Add a server associated to a subscriber in the list.
* @param s PresenceSubcription pointer.
*/
void addPresSubServer(PresSubServer* s);
/**
* IP2IP context.
* Remove a server associated to a subscriber from the list.
* @param s PresenceSubcription pointer.
*/
void removePresSubServer(PresSubServer* s);
/**
* IP2IP context.
* Iterate through the subscriber list and send NOTIFY to each.
*/
void notifyPresSubServer();
bool isEnabled() { return enabled_; }
bool isSupported(int function);
const std::list<PresSubClient*>& getClientSubscriptions() const { return sub_client_list_; }
bool isOnline() { return status_; }
std::string getNote() { return note_; }
void lock();
bool tryLock();
void unlock();
private:
NON_COPYABLE(SIPPresence);
static pj_status_t publish(SIPPresence* pres);
static void publish_cb(struct pjsip_publishc_cbparam* param);
static pj_status_t send_publish(SIPPresence* pres);
pjsip_publishc* publish_sess_; /**< Client publication session.*/
pjsip_pres_status status_data_; /**< Presence Data to be published.*/
pj_bool_t enabled_;
pj_bool_t publish_supported_; /**< the server allow for status publishing */
pj_bool_t subscribe_supported_; /**< the server allow for buddy subscription */
bool status_; /**< Status received from the server*/
std::string note_; /**< Note received from the server*/
SIPAccount* acc_; /**< Associated SIP account. */
std::list<PresSubServer*> sub_server_list_; /**< Subscribers list.*/
std::list<PresSubClient*> sub_client_list_; /**< Subcribed buddy list.*/
std::recursive_mutex mutex_;
pj_caching_pool cp_;
pj_pool_t* pool_;
};
} // namespace jami
#endif
| 6,866
|
C++
|
.h
| 200
| 29.735
| 96
| 0.669128
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,069
|
sipcall.h
|
savoirfairelinux_jami-daemon/src/sip/sipcall.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "call.h"
#include <dhtnet/ice_transport.h>
#include "connectivity/sip_utils.h"
#include "media/media_codec.h" // for MediaType enum
#include "sip/sdp.h"
#include "media/rtp_session.h"
#ifdef ENABLE_VIDEO
#include "media/video/video_receive_thread.h"
#include "media/video/video_rtp_session.h"
#endif
#ifdef ENABLE_PLUGIN
#include "plugin/streamdata.h"
#endif
#include "noncopyable.h"
#include <memory>
#include <optional>
extern "C" {
#include <pjsip/sip_config.h>
struct pjsip_evsub;
struct pjsip_inv_session;
struct pjmedia_sdp_session;
struct pj_ice_sess_cand;
struct pjsip_rx_data;
}
namespace dhtnet {
class IceSocket;
namespace upnp {
class Controller;
}
}
namespace jami {
class Sdp;
class SIPAccountBase;
class SipTransport;
class AudioRtpSession;
using IceCandidate = pj_ice_sess_cand;
/**
* @file sipcall.h
* @brief SIPCall are SIP implementation of a normal Call
*/
class SIPCall : public Call
{
private:
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
NON_COPYABLE(SIPCall);
public:
static constexpr LinkType LINK_TYPE = LinkType::SIP;
struct RtpStream
{
std::shared_ptr<RtpSession> rtpSession_ {};
std::shared_ptr<MediaAttribute> mediaAttribute_ {};
std::shared_ptr<MediaAttribute> remoteMediaAttribute_;
std::unique_ptr<dhtnet::IceSocket> rtpSocket_;
std::unique_ptr<dhtnet::IceSocket> rtcpSocket_;
};
/**
* Destructor
*/
~SIPCall();
/**
* Constructor
* @param id The call identifier
* @param type The type of the call (incoming/outgoing)
* @param mediaList A list of medias to include in the call
*/
SIPCall(const std::shared_ptr<SIPAccountBase>& account,
const std::string& id,
Call::CallType type,
const std::vector<libjami::MediaMap>& mediaList);
// Inherited from Call class
LinkType getLinkType() const override { return LINK_TYPE; }
// Override of Call class
private:
void merge(Call& call) override; // not public - only called by Call
public:
void answer() override;
void answer(const std::vector<libjami::MediaMap>& mediaList) override;
bool checkMediaChangeRequest(const std::vector<libjami::MediaMap>& remoteMediaList) override;
void handleMediaChangeRequest(const std::vector<libjami::MediaMap>& remoteMediaList) override;
void answerMediaChangeRequest(const std::vector<libjami::MediaMap>& mediaList,
bool isRemote = false) override;
void hangup(int reason) override;
void refuse() override;
void transfer(const std::string& to) override;
bool attendedTransfer(const std::string& to) override;
bool onhold(OnReadyCb&& cb) override;
bool offhold(OnReadyCb&& cb) override;
void switchInput(const std::string& resource = {}) override;
void peerHungup() override;
void carryingDTMFdigits(char code) override;
bool requestMediaChange(const std::vector<libjami::MediaMap>& mediaList) override;
std::vector<libjami::MediaMap> currentMediaList() const override;
void sendTextMessage(const std::map<std::string, std::string>& messages,
const std::string& from) override;
void removeCall() override;
void muteMedia(const std::string& mediaType, bool isMuted) override;
std::vector<MediaAttribute> getMediaAttributeList() const override;
std::map<std::string, bool> getAudioStreams() const override;
void restartMediaSender() override;
std::shared_ptr<SystemCodecInfo> getAudioCodec() const override;
std::shared_ptr<SystemCodecInfo> getVideoCodec() const override;
void sendKeyframe(int streamIdx = -1) override;
bool isIceEnabled() const override;
std::map<std::string, std::string> getDetails() const override;
void enterConference(std::shared_ptr<Conference> conference) override;
void exitConference() override;
#ifdef ENABLE_VIDEO
std::mutex sinksMtx_;
void createSinks(ConfInfo& infos) override;
std::map<std::string, std::shared_ptr<video::SinkClient>> callSinksMap_ {};
std::map<std::string, std::string> local2RemoteSinks_ {};
#endif
bool hasVideo() const override;
// TODO: cleanup this (used by conference + Call::getDetails() (and clients can use this))
bool isCaptureDeviceMuted(const MediaType& mediaType) const override;
bool isSrtpEnabled() const
{
return srtpEnabled_;
}
// End of override of Call class
// Override of Recordable class
bool toggleRecording() override;
// End of override of Recordable class
// Override PeerRecorder
void peerRecording(bool state) override;
void peerMuted(bool state, int streamIdx) override;
void peerVoice(bool state) override;
// end override PeerRecorder
void monitor() const override;
/**
* Set peer's User-Agent found in the message header
*/
void setPeerUaVersion(std::string_view ua);
/**
* Set peer's allowed methods
*/
void setPeerAllowMethods(std::vector<std::string> methods);
/**
* Check if a SIP method is allowed by peer
*/
bool isSipMethodAllowedByPeer(const std::string_view method) const;
/**
* Return the SDP's manager of this call
*/
Sdp& getSDP()
{
return *sdp_;
}
// Implementation of events reported by SipVoipLink.
/**
* Call is in ringing state on peer's side
*/
void onPeerRinging();
/**
* Peer answered the call
*/
void onAnswered();
/**
* Called to report server/internal errors
* @param cause Optional error code
*/
void onFailure(signed cause = 0);
/**
* Peer answered busy
*/
void onBusyHere();
/**
* Peer closed the connection
*/
void onClosed();
pj_status_t onReceiveReinvite(const pjmedia_sdp_session* offer, pjsip_rx_data* rdata);
void onReceiveOfferIn200OK(const pjmedia_sdp_session* offer);
/**
* Called when the media negotiation (SDP offer/answer) has
* completed.
*/
void onMediaNegotiationComplete();
// End fo SiPVoipLink events
const std::string& getContactHeader() const;
void setSipTransport(const std::shared_ptr<SipTransport>& transport,
const std::string& contactHdr = {});
SipTransport* getTransport()
{
return sipTransport_.get();
}
void sendSIPInfo(std::string_view body, std::string_view subtype);
void requestKeyframe(int streamIdx = -1);
void updateRecState(bool state) override;
std::shared_ptr<SIPAccountBase> getSIPAccount() const;
bool remoteHasValidIceAttributes() const;
void addLocalIceAttributes();
std::shared_ptr<dhtnet::IceTransport> getIceMedia() const
{
std::lock_guard lk(transportMtx_);
return reinvIceMedia_ ? reinvIceMedia_ : iceMedia_;
};
// Set ICE instance. Must be called only for sub-calls
void setIceMedia(std::shared_ptr<dhtnet::IceTransport> ice, bool isReinvite = false);
// Switch to re-invite ICE media if needed
void switchToIceReinviteIfNeeded();
/**
* Setup ICE locally to answer to an ICE offer. The ICE session has
* the controlled role (slave)
*/
void setupIceResponse(bool isReinvite = false);
void terminateSipSession(int status);
/**
* The invite session to be reused in case of transfer
*/
struct InvSessionDeleter
{
void operator()(pjsip_inv_session*) const noexcept;
};
#ifdef ENABLE_VIDEO
void setRotation(int streamIdx, int rotation);
#endif
// Get the list of current RTP sessions
std::vector<std::shared_ptr<RtpSession>> getRtpSessionList(
MediaType type = MediaType::MEDIA_ALL) const;
static size_t getActiveMediaStreamCount(const std::vector<MediaAttribute>& mediaAttrList);
void setActiveMediaStream(const std::string& accountUri,
const std::string& deviceId,
const std::string& streamId,
const bool& state);
void setPeerRegisteredName(const std::string& name)
{
peerRegisteredName_ = name;
}
void setPeerUri(const std::string& peerUri)
{
peerUri_ = peerUri;
}
std::string_view peerUri() const {
return peerUri_;
}
// Create a new ICE media session. If we already have an instance,
// it will be destroyed first.
bool createIceMediaTransport(bool isReinvite);
// Initialize the ICE session.
// The initialization is performed asynchronously, i.e, the instance
// may not be ready to use when this method returns.
bool initIceMediaTransport(bool master,
std::optional<dhtnet::IceTransportOptions> options = std::nullopt);
std::vector<std::string> getLocalIceCandidates(unsigned compId) const;
void setInviteSession(pjsip_inv_session* inviteSession = nullptr);
std::unique_ptr<pjsip_inv_session, InvSessionDeleter> inviteSession_;
inline std::weak_ptr<const SIPCall> weak() const
{
return std::weak_ptr<const SIPCall>(shared());
}
inline std::weak_ptr<SIPCall> weak()
{
return std::weak_ptr<SIPCall>(shared());
}
/**
* Announce to the client that medias are successfully negotiated
*/
void reportMediaNegotiationStatus();
private:
void generateMediaPorts();
void openPortsUPnP();
bool isIceRunning() const;
std::unique_ptr<dhtnet::IceSocket> newIceSocket(unsigned compId);
void deinitRecorder();
void rtpSetupSuccess();
void setupVoiceCallback(const std::shared_ptr<RtpSession>& rtpSession);
void sendMuteState(bool state);
void sendVoiceActivity(std::string_view streamId, bool state);
void resetTransport(std::shared_ptr<dhtnet::IceTransport>&& transport);
/**
* Send device orientation through SIP INFO
* @param streamIdx The stream to rotate
* @param rotation Device orientation (0/90/180/270) (counterclockwise)
*/
void setVideoOrientation(int streamIdx, int rotation);
mutable std::mutex transportMtx_ {};
#ifdef ENABLE_PLUGIN
/**
* Call Streams and some typedefs
*/
using AVMediaStream = Observable<std::shared_ptr<MediaFrame>>;
using MediaStreamSubject = PublishMapSubject<std::shared_ptr<MediaFrame>, AVFrame*>;
/**
* @brief createCallAVStream
* Creates a call AV stream like video input, video receive, audio input or audio receive
* @param StreamData The type of the stream (audio/video, input/output,
* @param streamSource
* @param mediaStreamSubject
*/
void createCallAVStream(const StreamData& StreamData,
AVMediaStream& streamSource,
const std::shared_ptr<MediaStreamSubject>& mediaStreamSubject);
/**
* @brief createCallAVStreams
* Creates all Call AV Streams (2 if audio, 4 if audio video)
*/
void createCallAVStreams();
/**
* @brief Detach all plugins from call streams;
*/
void clearCallAVStreams();
std::mutex avStreamsMtx_ {};
std::map<std::string, std::shared_ptr<MediaStreamSubject>> callAVStreams;
#endif // ENABLE_PLUGIN
void setCallMediaLocal();
void startIceMedia();
void onIceNegoSucceed();
void setupNegotiatedMedia();
void startAllMedia();
void stopAllMedia();
void updateRemoteMedia();
/**
* Transfer method used for both type of transfer
*/
bool transferCommon(const pj_str_t* dst);
bool internalOffHold(const std::function<void()>& SDPUpdateFunc);
bool hold();
bool unhold();
// Update the attributes of a media stream
void updateMediaStream(const MediaAttribute& newMediaAttr, size_t streamIdx);
bool updateAllMediaStreams(const std::vector<MediaAttribute>& mediaAttrList, bool isRemote);
// Check if a SIP re-invite must be sent to negotiate the new media
bool isReinviteRequired(const std::vector<MediaAttribute>& mediaAttrList);
// Check if a new ICE media session is needed when performing a re-invite
bool isNewIceMediaRequired(const std::vector<MediaAttribute>& mediaAttrList);
void requestReinvite(const std::vector<MediaAttribute>& mediaAttrList, bool needNewIce);
int SIPSessionReinvite(const std::vector<MediaAttribute>& mediaAttrList, bool needNewIce);
int SIPSessionReinvite();
// Add a media stream to the call.
void addMediaStream(const MediaAttribute& mediaAttr);
// Init media streams
size_t initMediaStreams(const std::vector<MediaAttribute>& mediaAttrList);
// Create a new stream from SDP description.
void createRtpSession(RtpStream& rtpStream);
// Configure the RTP session from SDP description.
void configureRtpSession(const std::shared_ptr<RtpSession>& rtpSession,
const std::shared_ptr<MediaAttribute>& mediaAttr,
const MediaDescription& localMedia,
const MediaDescription& remoteMedia);
// Find the stream index with the matching label
int findRtpStreamIndex(const std::string& label) const;
std::vector<IceCandidate> getAllRemoteCandidates(dhtnet::IceTransport& transport) const;
inline std::shared_ptr<const SIPCall> shared() const
{
return std::static_pointer_cast<const SIPCall>(shared_from_this());
}
inline std::shared_ptr<SIPCall> shared()
{
return std::static_pointer_cast<SIPCall>(shared_from_this());
}
// Peer's User-Agent.
std::string peerUserAgent_ {};
// Flag to indicate if the peer's Daemon version supports multi-stream.
bool peerSupportMultiStream_ {false};
// Flag to indicate if the peer's Daemon version supports multi-stream.
bool peerSupportMultiAudioStream_ {false};
// Flag to indicate if the peer's Daemon version can negotiate more than 2 ICE medias
bool peerSupportMultiIce_ {false};
// Flag to indicate if the peer's Daemon version supports re-invite
// without ICE renegotiation.
bool peerSupportReuseIceInReinv_ {false};
// Peer's allowed methods.
std::vector<std::string> peerAllowedMethods_;
// Vector holding the current RTP sessions.
std::vector<RtpStream> rtpStreams_;
/**
* Hold the transport used for SIP communication.
* Will be different from the account registration transport for
* non-IP2IP calls.
*/
std::shared_ptr<SipTransport> sipTransport_ {};
/**
* The SDP session
*/
std::unique_ptr<Sdp> sdp_ {};
bool peerHolding_ {false};
bool isWaitingForIceAndMedia_ {false};
enum class Request { HoldingOn, HoldingOff, SwitchInput, NoRequest };
Request remainingRequest_ {Request::NoRequest};
std::string peerRegisteredName_ {};
std::string contactHeader_ {};
std::shared_ptr<dhtnet::upnp::Controller> upnp_;
/** Local audio port, as seen by me. */
unsigned int localAudioPort_ {0};
/** Local video port, as seen by me. */
unsigned int localVideoPort_ {0};
bool mediaRestartRequired_ {true};
bool enableIce_ {true};
bool srtpEnabled_ {false};
bool rtcpMuxEnabled_ {false};
// ICE media transport
std::shared_ptr<dhtnet::IceTransport> iceMedia_;
// Re-invite (temporary) ICE media transport.
std::shared_ptr<dhtnet::IceTransport> reinvIceMedia_;
std::string peerUri_ {};
bool readyToRecord_ {false};
bool pendingRecord_ {false};
time_point lastKeyFrameReq_ {time_point::min()};
OnReadyCb holdCb_ {};
OnReadyCb offHoldCb_ {};
std::atomic_bool waitForIceInit_ {false};
void detachAudioFromConference();
std::mutex setupSuccessMutex_;
#ifdef ENABLE_VIDEO
int rotation_ {0};
#endif
std::string mediaPlayerId_ {};
};
// Helpers
/**
* Obtain a shared smart pointer of instance
*/
inline std::shared_ptr<SIPCall>
getPtr(SIPCall& call)
{
return std::static_pointer_cast<SIPCall>(call.shared_from_this());
}
} // namespace jami
| 16,886
|
C++
|
.h
| 439
| 32.915718
| 98
| 0.699456
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,070
|
siptransport.h
|
savoirfairelinux_jami-daemon/src/sip/siptransport.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "connectivity/sip_utils.h"
#include "noncopyable.h"
#include "logger.h"
#include <pjsip.h>
#include <pjnath/stun_config.h>
#include <functional>
#include <mutex>
#include <condition_variable>
#include <map>
#include <string>
#include <vector>
#include <list>
#include <memory>
// OpenDHT
namespace dht {
namespace crypto {
struct Certificate;
}
} // namespace dht
namespace dhtnet {
class ChannelSocket;
} // namespace dhtnet
namespace jami {
class SIPAccountBase;
using onShutdownCb = std::function<void(void)>;
struct TlsListener
{
TlsListener() {}
TlsListener(pjsip_tpfactory* f)
: listener(f)
{}
virtual ~TlsListener()
{
JAMI_DBG("Destroying listener");
listener->destroy(listener);
}
pjsip_tpfactory* get() { return listener; }
private:
NON_COPYABLE(TlsListener);
pjsip_tpfactory* listener {nullptr};
};
struct TlsInfos
{
pj_ssl_cipher cipher {PJ_TLS_UNKNOWN_CIPHER};
pj_ssl_sock_proto proto {PJ_SSL_SOCK_PROTO_DEFAULT};
pj_ssl_cert_verify_flag_t verifyStatus {};
std::shared_ptr<dht::crypto::Certificate> peerCert {};
};
using SipTransportStateCallback
= std::function<void(pjsip_transport_state, const pjsip_transport_state_info*)>;
/**
* SIP transport wraps pjsip_transport.
*/
class SipTransport
{
public:
SipTransport(pjsip_transport*);
SipTransport(pjsip_transport*, const std::shared_ptr<TlsListener>&);
// If the SipTransport is a channeled transport, we are already connected to the peer,
// so, we can directly set tlsInfos_.peerCert and avoid any copy
SipTransport(pjsip_transport* t,
const std::shared_ptr<dht::crypto::Certificate>& peerCertficate);
~SipTransport();
static const char* stateToStr(pjsip_transport_state state);
void stateCallback(pjsip_transport_state state, const pjsip_transport_state_info* info);
pjsip_transport* get() { return transport_.get(); }
void addStateListener(uintptr_t lid, SipTransportStateCallback cb);
bool removeStateListener(uintptr_t lid);
bool isSecure() const { return PJSIP_TRANSPORT_IS_SECURE(transport_); }
const TlsInfos& getTlsInfos() const { return tlsInfos_; }
static bool isAlive(pjsip_transport_state state);
/** Only makes sense for connection-oriented transports */
bool isConnected() const noexcept { return connected_; }
inline void setDeviceId(const std::string& deviceId) { deviceId_ = deviceId; }
inline std::string_view deviceId() const { return deviceId_; }
inline void setAccount(const std::shared_ptr<SIPAccountBase>& account) { account_ = account; }
inline const std::weak_ptr<SIPAccountBase>& getAccount() const { return account_; }
uint16_t getTlsMtu();
private:
NON_COPYABLE(SipTransport);
static void deleteTransport(pjsip_transport* t);
std::unique_ptr<pjsip_transport, decltype(deleteTransport)&> transport_;
std::shared_ptr<TlsListener> tlsListener_;
std::mutex stateListenersMutex_;
std::map<uintptr_t, SipTransportStateCallback> stateListeners_;
std::weak_ptr<SIPAccountBase> account_ {};
bool connected_ {false};
std::string deviceId_ {};
TlsInfos tlsInfos_;
};
class IceTransport;
namespace tls {
struct TlsParams;
};
/**
* Manages the transports and receive callbacks from PJSIP
*/
class SipTransportBroker
{
public:
SipTransportBroker(pjsip_endpoint* endpt);
~SipTransportBroker();
std::shared_ptr<SipTransport> getUdpTransport(const dhtnet::IpAddr&);
std::shared_ptr<TlsListener> getTlsListener(const dhtnet::IpAddr&, const pjsip_tls_setting*);
std::shared_ptr<SipTransport> getTlsTransport(const std::shared_ptr<TlsListener>&,
const dhtnet::IpAddr& remote,
const std::string& remote_name = {});
std::shared_ptr<SipTransport> addTransport(pjsip_transport*);
std::shared_ptr<SipTransport> getChanneledTransport(
const std::shared_ptr<SIPAccountBase>& account,
const std::shared_ptr<dhtnet::ChannelSocket>& socket,
onShutdownCb&& cb);
/**
* Start graceful shutdown procedure for all transports
*/
void shutdown();
void transportStateChanged(pjsip_transport*,
pjsip_transport_state,
const pjsip_transport_state_info*);
private:
NON_COPYABLE(SipTransportBroker);
/**
* Create SIP UDP transport from account's setting
* @param account The account for which a transport must be created.
* @param IP protocol version to use, can be pj_AF_INET() or pj_AF_INET6()
* @return a pointer to the new transport
*/
std::shared_ptr<SipTransport> createUdpTransport(const dhtnet::IpAddr&);
/**
* List of transports so we can bubble the events up.
*/
std::map<pjsip_transport*, std::weak_ptr<SipTransport>> transports_ {};
std::mutex transportMapMutex_ {};
/**
* Transports are stored in this map in order to retrieve them in case
* several accounts would share the same port number.
*/
std::map<dhtnet::IpAddr, pjsip_transport*> udpTransports_;
pjsip_endpoint* endpt_;
std::atomic_bool isDestroying_ {false};
};
} // namespace jami
| 6,086
|
C++
|
.h
| 162
| 32.808642
| 98
| 0.708723
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,071
|
sipvoiplink.h
|
savoirfairelinux_jami-daemon/src/sip/sipvoiplink.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ring_types.h"
#include "noncopyable.h"
#include <dhtnet/ip_utils.h>
#include <pjsip.h>
#include <pjlib.h>
#include <pjsip_ua.h>
#include <pjlib-util.h>
#include <pjnath.h>
#include <pjnath/stun_config.h>
#ifdef ENABLE_VIDEO
#include <queue>
#endif
#include <map>
#include <mutex>
#include <memory>
#include <functional>
#include <thread>
#include <atomic>
namespace jami {
class SIPCall;
class SIPAccountBase;
class SIPVoIPLink;
class SipTransportBroker;
/**
* @file sipvoiplink.h
* @brief Specific VoIPLink for SIP (SIP core for incoming and outgoing events).
*/
class SIPVoIPLink
{
public:
SIPVoIPLink();
~SIPVoIPLink();
/**
* Destroy structures
*/
void shutdown();
/**
* Event listener. Each event send by the call manager is received and handled from here
*/
void handleEvents();
/**
* Register a new keepalive registration timer to this endpoint
*/
void registerKeepAliveTimer(pj_timer_entry& timer, pj_time_val& delay);
/**
* Abort currently registered timer
*/
void cancelKeepAliveTimer(pj_timer_entry& timer);
/**
* Get the memory pool factory since each calls has its own memory pool
*/
pj_caching_pool* getMemoryPoolFactory();
/**
* Create the default UDP transport according ot Ip2Ip profile settings
*/
void createDefaultSipUdpTransport();
public:
static void createSDPOffer(pjsip_inv_session* inv);
/**
* Instance that maintain and manage transport (UDP, TLS)
*/
std::unique_ptr<SipTransportBroker> sipTransportBroker;
typedef std::function<void(std::vector<dhtnet::IpAddr>)> SrvResolveCallback;
void resolveSrvName(const std::string& name,
pjsip_transport_type_e type,
SrvResolveCallback&& cb);
/**
* Guess the account related to an incoming SIP call.
*/
std::shared_ptr<SIPAccountBase> guessAccount(std::string_view userName,
std::string_view server,
std::string_view fromUri) const;
int getModId();
pjsip_endpoint* getEndpoint();
pjsip_module* getMod();
pj_caching_pool* getCachingPool() noexcept;
pj_pool_t* getPool() noexcept;
/**
* Get the correct address to use (ie advertised) from
* a uri. The corresponding transport that should be used
* with that uri will be discovered.
*
* @param uri The uri from which we want to discover the address to use
* @param transport The transport to use to discover the address
*/
void findLocalAddressFromTransport(pjsip_transport* transport,
pjsip_transport_type_e transportType,
const std::string& host,
std::string& address,
pj_uint16_t& port) const;
bool findLocalAddressFromSTUN(pjsip_transport* transport,
pj_str_t* stunServerName,
int stunPort,
std::string& address,
pj_uint16_t& port) const;
/**
* Initialize the transport selector
* @param transport A transport associated with an account
* @return A transport selector structure
*/
static inline pjsip_tpselector getTransportSelector(pjsip_transport* transport)
{
pjsip_tpselector tp;
tp.type = PJSIP_TPSELECTOR_TRANSPORT;
tp.u.transport = transport;
return tp;
}
private:
NON_COPYABLE(SIPVoIPLink);
mutable pj_caching_pool cp_;
std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&> pool_;
std::atomic_bool running_ {true};
std::thread sipThread_;
friend class SIPTest;
};
} // namespace jami
| 4,704
|
C++
|
.h
| 136
| 27.654412
| 92
| 0.648238
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,072
|
videomanager.h
|
savoirfairelinux_jami-daemon/src/client/videomanager.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <memory> // for weak/shared_ptr
#include <vector>
#include <map>
#include <mutex>
#include <string>
#include "media/audio/audio_input.h"
#ifdef ENABLE_VIDEO
#include "media/video/video_device_monitor.h"
#include "media/video/video_base.h"
#include "media/video/video_input.h"
#endif
#include "media/media_player.h"
namespace jami {
struct VideoManager
{
public:
// Client-managed video inputs and players
std::map<std::string, std::shared_ptr<MediaPlayer>> mediaPlayers;
// Client-managed audio preview
std::shared_ptr<AudioInput> audioPreview;
#ifdef ENABLE_VIDEO
std::map<std::string, std::shared_ptr<video::VideoInput>> clientVideoInputs;
void setDeviceOrientation(const std::string& deviceId, int angle);
// device monitor
video::VideoDeviceMonitor videoDeviceMonitor;
std::shared_ptr<video::VideoInput> getVideoInput(std::string_view id) const
{
auto input = videoInputs.find(id);
return input == videoInputs.end() ? nullptr : input->second.lock();
}
std::mutex videoMutex;
std::map<std::string, std::weak_ptr<video::VideoInput>, std::less<>> videoInputs;
#endif
/**
* Cache of the active Audio/Video input(s).
*/
std::map<std::string, std::weak_ptr<AudioInput>, std::less<>> audioInputs;
std::mutex audioMutex;
bool hasRunningPlayers();
};
#ifdef ENABLE_VIDEO
video::VideoDeviceMonitor& getVideoDeviceMonitor();
std::shared_ptr<video::VideoInput> getVideoInput(
const std::string& resource,
video::VideoInputMode inputMode = video::VideoInputMode::Undefined,
const std::string& sink = "");
#endif
std::shared_ptr<AudioInput> getAudioInput(const std::string& device);
std::string createMediaPlayer(const std::string& path);
std::shared_ptr<MediaPlayer> getMediaPlayer(const std::string& id);
bool pausePlayer(const std::string& id, bool pause);
bool closeMediaPlayer(const std::string& id);
bool mutePlayerAudio(const std::string& id, bool mute);
bool playerSeekToTime(const std::string& id, int time);
int64_t getPlayerPosition(const std::string& id);
int64_t getPlayerDuration(const std::string& id);
void setAutoRestart(const std::string& id, bool restart);
} // namespace jami
| 2,988
|
C++
|
.h
| 78
| 35.641026
| 85
| 0.74526
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,073
|
ring_signal.h
|
savoirfairelinux_jami-daemon/src/client/ring_signal.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "callmanager_interface.h"
#include "configurationmanager_interface.h"
#include "conversation_interface.h"
#include "presencemanager_interface.h"
#include "datatransfer_interface.h"
#ifdef ENABLE_VIDEO
#include "videomanager_interface.h"
#endif
#ifdef ENABLE_PLUGIN
#include "plugin_manager_interface.h"
#endif
#include "jami.h"
#include "logger.h"
#include "trace-tools.h"
#include "tracepoint.h"
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#include <exception>
#include <memory>
#include <map>
#include <utility>
#include <string>
namespace jami {
using SignalHandlerMap = std::map<std::string, std::shared_ptr<libjami::CallbackWrapperBase>>;
extern SignalHandlerMap& getSignalHandlers();
/*
* Find related user given callback and call it with given
* arguments.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template<typename Ts, typename... Args>
void emitSignal(Args... args)
{
jami_tracepoint_if_enabled(emit_signal, demangle<Ts>().c_str());
const auto& handlers = getSignalHandlers();
if (auto wrap = libjami::CallbackWrapper<typename Ts::cb_type>(handlers.at(Ts::name))) {
try {
auto cb = *wrap;
jami_tracepoint(emit_signal_begin_callback,
wrap.file_, wrap.linum_);
cb(args...);
jami_tracepoint(emit_signal_end_callback);
} catch (std::exception& e) {
JAMI_ERR("Exception during emit signal %s:\n%s", Ts::name, e.what());
}
}
jami_tracepoint(emit_signal_end);
}
#pragma GCC diagnostic pop
template<typename Ts>
std::pair<std::string, std::shared_ptr<libjami::CallbackWrapper<typename Ts::cb_type>>>
exported_callback()
{
return std::make_pair((const std::string&) Ts::name,
std::make_shared<libjami::CallbackWrapper<typename Ts::cb_type>>());
}
} // namespace jami
| 2,687
|
C++
|
.h
| 79
| 30.556962
| 94
| 0.717039
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,074
|
CSVExporter.cpp
|
Wargus_stargus/test/gamedata/dat/CSVExporter.cpp
|
/*
* CSVExporter.cpp
*
* Author: Andreas Volz
*/
// project
#include "CSVExporter.h"
#include "dat/Unit.h"
// system
#include <vector>
#include <iostream>
#include <string>
using namespace std;
using namespace dat;
static const int units_units_ready_sound_end = 106;
CSVExporter::CSVExporter(DataHub &datahub) :
mDatahub(datahub)
{
}
CSVExporter::~CSVExporter()
{
}
void CSVExporter::print()
{
string csv_dat;
char buf[1024];
const string CSV_ENDLINE = "\n";
const string CSV_SEPARATOR = ";";
std::vector<uint32_t> *sfxdata_sound_file_vec;
std::vector<uint32_t> *mapdata_mission_dir_vec;
// units.dat
std::vector<uint8_t> *units_graphics_vec = mDatahub.units->flingy();
std::vector<uint8_t> *units_ground_weapon_vec = mDatahub.units->ground_weapon();
std::vector<units_dat_t::staredit_group_flags_type_t *> *se_group_flags_vec =
mDatahub.units->staredit_group_flags();
std::vector<uint16_t> *units_ready_sound_vec = mDatahub.units->ready_sound();
std::vector<uint16_t> *units_portrait_vec = mDatahub.units->portrait();
std::vector<uint8_t> *units_armor_upgrade_vec = mDatahub.units->armor_upgrade();
// orders.dat
std::vector<uint16_t> *orders_label_vec = mDatahub.orders->label();
// weapons.dat
std::vector<uint16_t> *weapon_label_vec = mDatahub.weapons->label();
std::vector<uint32_t> *weapon_graphics_vec = mDatahub.weapons->graphics();
std::vector<uint16_t> *weapon_error_message_vec = mDatahub.weapons->error_message();
std::vector<uint16_t> *flingy_sprites_vec = mDatahub.flingy->sprite();
// sprites.dat
std::vector<uint16_t> *sprites_images_vec = mDatahub.sprites->image();
std::vector<uint32_t> *images_grp_vec = mDatahub.images->grp();
sfxdata_sound_file_vec = mDatahub.sfxdata->sound_file();
std::vector<uint32_t> *portdata_portrait_idle_vec = mDatahub.portdata->video_idle();
std::vector<uint32_t> *portdata_portrait_talking_vec = mDatahub.portdata->video_talking();
// upgrades.dat
std::vector<uint16_t> *upgrades_label_vec = mDatahub.upgrades->label();
// techdata.dat
std::vector<uint16_t> *techdata_label_vec = mDatahub.techdata->label();
// mapdata.dat
mapdata_mission_dir_vec = mDatahub.mapdata->mission_dir();
// images.dat
std::vector<images_dat_t::draw_function_enum_t> *images_draw_function = mDatahub.images->draw_function();
std::vector<images_dat_t::remapping_enum_t> *images_remapping_function = mDatahub.images->remapping();
// units.dat
for (unsigned int i = 0; i < units_graphics_vec->size(); i++)
{
csv_dat += "units.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint8_t graphic_id = units_graphics_vec->at(i);
sprintf(buf, "graphics=%d", graphic_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
units_dat_t::staredit_group_flags_type_t *se_group_flags =
se_group_flags_vec->at(i);
bool zerg = se_group_flags->zerg();
bool terran = se_group_flags->terran();
bool protoss = se_group_flags->protoss();
if (zerg)
{
csv_dat += "race=zerg";
}
else if (terran)
{
csv_dat += "race=terran";
}
else if (protoss)
{
csv_dat += "race=protoss";
}
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.stat_txt_units_tbl_vec.at(i);
csv_dat += "ref:name=" + tblEntry.name1;
csv_dat += CSV_SEPARATOR;
uint16_t sprite_id = flingy_sprites_vec->at(graphic_id);
sprintf(buf, "ref:sprite=%d", sprite_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
uint16_t weapon_id = units_ground_weapon_vec->at(i);
sprintf(buf, "weapon=%d", weapon_id);
csv_dat += buf;
if (i < units_units_ready_sound_end)
{
csv_dat += CSV_SEPARATOR;
uint16_t ready_sound_id = units_ready_sound_vec->at(i);
sprintf(buf, "ready_sound=%d", ready_sound_id);
csv_dat += buf;
}
csv_dat += CSV_SEPARATOR;
uint32_t units_portrait_file = units_portrait_vec->at(i);
sprintf(buf, "portrait=%d", units_portrait_file);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
if (units_portrait_file != Unit::portrait_none)
{
uint32_t portrait_file = portdata_portrait_idle_vec->at(units_portrait_file);
sprintf(buf, "ref:portrait_idle_file=%d", portrait_file - 1);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry_portrait = mDatahub.portdata_tbl_vec.at(portrait_file - 1);
csv_dat += "ref:portrait_idle=" + tblEntry_portrait.name1;
csv_dat += CSV_SEPARATOR;
}
if (units_portrait_file != Unit::portrait_none)
{
uint32_t portrait_file = portdata_portrait_talking_vec->at(units_portrait_file);
sprintf(buf, "ref:portrait_talking_file=%d", portrait_file);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry_portrait = mDatahub.portdata_tbl_vec.at(portrait_file - 1);
csv_dat += "ref:portrait_talking=" + tblEntry_portrait.name1;
csv_dat += CSV_SEPARATOR;
}
csv_dat += CSV_SEPARATOR;
uint8_t units_armor_upgrade = units_armor_upgrade_vec->at(i);
sprintf(buf, "units_armor_upgrade=%d", units_armor_upgrade);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// weapons.dat
for (unsigned int i = 0; i < weapon_label_vec->size(); i++)
{
csv_dat += "weapons.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t label_id = weapon_label_vec->at(i);
sprintf(buf, "label=%d", label_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry_label = mDatahub.stat_txt_tbl_vec.at(label_id);
csv_dat += "ref:name=" + tblEntry_label.name1;
csv_dat += CSV_SEPARATOR;
uint32_t graphic = weapon_graphics_vec->at(i);
sprintf(buf, "graphics=%d", graphic);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
uint16_t error_id = weapon_error_message_vec->at(i);
sprintf(buf, "error_id=%d", error_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry_error = mDatahub.stat_txt_tbl_vec.at(error_id);
csv_dat += " ref:error_text=" + tblEntry_error.name1;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// flingy.dat
for (unsigned int i = 0; i < flingy_sprites_vec->size(); i++)
{
csv_dat += "flingy.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t flingy_id = flingy_sprites_vec->at(i);
sprintf(buf, "sprite=%d", flingy_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// sprites.dat
for (unsigned int i = 0; i < sprites_images_vec->size(); i++)
{
csv_dat += "sprites.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t image_id = sprites_images_vec->at(i);
sprintf(buf, "images_file=%d", image_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// images.dat
for (unsigned int i = 0; i < images_grp_vec->size(); i++)
{
csv_dat += "images.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t grp_id = images_grp_vec->at(i);
sprintf(buf, "grp_file=%d", grp_id);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.images_tbl_vec.at(grp_id - 1); // spec says first index is -1
csv_dat += "ref:name=" + tblEntry.name1;
csv_dat += CSV_SEPARATOR;
csv_dat += "ref:draw_function=" + to_string(images_draw_function->at(i));
csv_dat += CSV_SEPARATOR;
csv_dat += "ref:remapping_function=" + to_string(images_remapping_function->at(i));
csv_dat += CSV_ENDLINE;
}
// sfxdata.dat
for (unsigned int i = 0; i < sfxdata_sound_file_vec->size()-1; i++)
{
csv_dat += "sfxdata.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint32_t sound_file = sfxdata_sound_file_vec->at(i);
sprintf(buf, "sound_file=%d", sound_file);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.sfxdata_tbl_vec.at(sound_file);
csv_dat += "ref:name=" + tblEntry.name1;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// portrait.dat
for (unsigned int i = 0; i < portdata_portrait_idle_vec->size(); i++)
{
csv_dat += "portrait.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint32_t portrait_idle = portdata_portrait_idle_vec->at(i);
sprintf(buf, "portrait_idle=%d", portrait_idle);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry_idle = mDatahub.portdata_tbl_vec.at(portrait_idle - 1);
csv_dat += "ref:idle=" + tblEntry_idle.name1;
csv_dat += CSV_SEPARATOR;
uint32_t portrait_talking = portdata_portrait_talking_vec->at(i);
sprintf(buf, "portrait_talking=%d", portrait_talking);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry_talking = mDatahub.portdata_tbl_vec.at(portrait_talking - 1);
csv_dat += "ref:talking=" + tblEntry_talking.name1;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// upgrades.dat
for (unsigned int i = 0; i < upgrades_label_vec->size(); i++)
{
csv_dat += "upgrades.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t upgrades_label = upgrades_label_vec->at(i);
sprintf(buf, "upgrades_label=%d", upgrades_label);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.stat_txt_tbl_vec.at(upgrades_label);
csv_dat += "ref:label=" + tblEntry.name1;
sprintf(buf, "ref:shortcut=%s", tblEntry.shortcut.c_str());
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// orders.dat
for (unsigned int i = 0; i < orders_label_vec->size(); i++)
{
csv_dat += "orders.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t orders_label = orders_label_vec->at(i);
sprintf(buf, "orders_label=%d", orders_label);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.stat_txt_tbl_vec.at(orders_label);
csv_dat += "ref:label=" + tblEntry.name1;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// techdata.dat
for (unsigned int i = 0; i < techdata_label_vec->size(); i++)
{
csv_dat += "techdata.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint16_t techdata_label = techdata_label_vec->at(i);
sprintf(buf, "techdata_label=%d", techdata_label);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.stat_txt_tbl_vec.at(techdata_label);
csv_dat += "ref:label=" + tblEntry.name1;
csv_dat += CSV_SEPARATOR;
sprintf(buf, "ref:shortcut=%s", tblEntry.shortcut.c_str());
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
sprintf(buf, "ref:shortcut_pos=%d", tblEntry.shortcut_pos);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// mapdata.dat
for (unsigned int i = 0; i < mapdata_mission_dir_vec->size(); i++)
{
csv_dat += "mapdata.dat";
csv_dat += CSV_SEPARATOR;
csv_dat += "id=" + to_string(i);
csv_dat += CSV_SEPARATOR;
uint32_t mapdata_label = mapdata_mission_dir_vec->at(i);
sprintf(buf, "mapdata_label=%d", mapdata_label);
csv_dat += buf;
csv_dat += CSV_SEPARATOR;
TblEntry tblEntry = mDatahub.mapdata_tbl_vec.at(mapdata_label - 1);
csv_dat += "ref:dir=" + tblEntry.name1;
csv_dat += CSV_SEPARATOR;
csv_dat += CSV_ENDLINE;
}
// stdout
cout << csv_dat;
}
| 11,896
|
C++
|
.cpp
| 324
| 31.895062
| 107
| 0.641594
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,075
|
DatTest.cpp
|
Wargus_stargus/test/gamedata/dat/DatTest.cpp
|
/*
* DatTest.cpp
*
* Author: Andreas Volz
*/
// project
#include "dat/DataHub.h"
#include "CSVExporter.h"
#include "Breeze.h"
#include "FileUtil.h"
#include "Logger.h"
#include "optparser.h"
// system
#include <iostream>
using namespace std;
// some global variables
static Logger logger("startool.DatTest");
string dat_files_directory;
/** option parser **/
struct Arg: public option::Arg
{
static void printError(const char *msg1, const option::Option &opt, const char *msg2)
{
fprintf(stderr, "%s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(const option::Option &option, bool msg)
{
if (msg)
printError("Unknown option '", option, "'\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(const option::Option &option, bool msg)
{
if (option.arg != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires an argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus NonEmpty(const option::Option &option, bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a non-empty argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(const option::Option &option, bool msg)
{
char *endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10))
{
};
if (endptr != option.arg && *endptr == 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a numeric argument\n");
return option::ARG_ILLEGAL;
}
};
enum optionIndex
{
UNKNOWN, HELP
};
const option::Descriptor usage[] =
{
{
UNKNOWN, 0, "", "", option::Arg::None, "USAGE: DatTest <dat_files_directory>\n\n"
"Options:"
},
{ HELP, 0, "h", "help", option::Arg::None, " --help, -h \t\tPrint usage and exit" }, {
UNKNOWN, 0, "", "", option::Arg::None,
"\ndat_files_directory \t\tDirectory which contain the extracted stardat.mpq files with arr/*.dat inside...\n"
},
{ 0, 0, 0, 0, 0, 0 }
};
int parseOptions(int argc, const char **argv)
{
argc -= (argc > 0);
argv += (argc > 0); // skip program name argv[0] if present
option::Stats stats(usage, argc, argv);
std::unique_ptr<option::Option[]> options(new option::Option[stats.options_max]), buffer(new option::Option[stats.buffer_max]);
option::Parser parse(usage, argc, argv, options.get(), buffer.get());
if (parse.error())
exit(0);
if (options[HELP])
{
option::printUsage(std::cout, usage);
exit(0);
}
// parse options
for (option::Option *opt = options[UNKNOWN]; opt; opt = opt->next())
std::cout << "Unknown option: " << opt->name << "\n";
for (int i = 0; i < parse.nonOptionsCount(); ++i)
{
switch (i)
{
case 0:
cerr << "archive-directory #" << i << ": " << parse.nonOption(i) << "\n";
dat_files_directory = parse.nonOption(i);
break;
default:
break;
}
}
if (dat_files_directory.empty())
{
cerr << "Error: 'dat_files_directory' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
return 0;
}
int main(int argc, const char **argv)
{
#ifdef HAVE_LOG4CXX
if (FileExists("logging.prop"))
{
log4cxx::PropertyConfigurator::configure("logging.prop");
}
else
{
logger.off();
}
#endif // HAVE_LOG4CXX
parseOptions(argc, argv);
shared_ptr<Breeze> storm = make_shared<Breeze>(dat_files_directory);
dat::DataHub datahub(storm);
CSVExporter csvexporter(datahub);
csvexporter.print();
return 0;
}
| 3,705
|
C++
|
.cpp
| 134
| 24.052239
| 129
| 0.642554
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,076
|
CreateUnitLuaTest.cpp
|
Wargus_stargus/test/lua/CreateUnitLuaTest.cpp
|
/*
* CreateUnitLuaTest.cpp
*
* Author: Andreas Volz
*/
// project
#include "CreateUnitLuaTest.h"
#include "luagen.h"
#include "Storage.h"
#include "FileUtil.h"
// system
#include <iostream>
#include <fstream>
#include <memory>
using namespace std;
CreateUnitLuaTest::CreateUnitLuaTest(json &unitsJson)
{
Storage luagen;
luagen.setDataPath("data"); // FIXME for now need to copy this manually into your data directory
luagen.setDataType("luagen/tests");
CheckPath(luagen.getFullPath());
Storage lua_file_store(luagen("CreateUnitLuaTest.lua"));
ofstream lua_file;
lua_file.open (lua_file_store.getFullPath());
lua_file << lg::line("function CreateUnitLuaTest_intern(unit, part)");
lua_file << lg::line(" if not part then part = \"\" end");
lua_file << lg::line(" if string.find(unit, part) then");
lua_file << lg::line(" print('CreateUnit(\"' .. unit .. '\", 0, {0, 0})')");
lua_file << lg::line(" CreateUnit(unit, 0, {0, 0})");
lua_file << lg::line(" end");
lua_file << lg::line("end");
lua_file << lg::line("function CreateUnitLuaTest(part)");
unsigned int end = 0;
for(auto &array : unitsJson)
{
string unit_name = array.at("name");
// intermediate solution to jump over (currently/not yet) known not working units
vector<string> brokenUnits({
});
if(std::find(brokenUnits.begin(), brokenUnits.end(), unit_name) == brokenUnits.end())
{
//string create_unit = lg::CreateUnit(unit_name, 0, Pos(0,0));
string create_unit = lg::function("CreateUnitLuaTest_intern", {lg::singleQuote(unit_name), "part"});
lua_file << create_unit << endl;
}
end++;
}
lua_file << lg::line("end");
lua_file.close();
}
CreateUnitLuaTest::~CreateUnitLuaTest()
{
}
| 1,769
|
C++
|
.cpp
| 53
| 30.169811
| 106
| 0.669617
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,077
|
LuaTest.cpp
|
Wargus_stargus/test/lua/LuaTest.cpp
|
/*
* LuaTest.cpp
*
* Author: Andreas Volz
*/
// project
#include "CreateUnitLuaTest.h"
// system
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
// read in the json file
std::ifstream json_file("dataset/units.json");
json units_json;
json_file >> units_json;
cout << "Run CreateUnitLuaTest..." << endl;
CreateUnitLuaTest createUnitLuaTest(units_json);
return 0;
}
| 441
|
C++
|
.cpp
| 21
| 18.761905
| 50
| 0.711165
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,079
|
DataChunkTest.cpp
|
Wargus_stargus/test/module/DataChunkTest.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// System
// Project
#include "DataChunkTest.h"
#include "platform.h"
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(DataChunkTest);
void DataChunkTest::setUp()
{
}
void DataChunkTest::tearDown()
{
}
void DataChunkTest::test1_addData()
{
DataChunk dc;
int LENGTH = 5;
unsigned char rawdata[LENGTH];
rawdata[0] = 0x1;
rawdata[1] = 0x2;
rawdata[2] = 0x3;
rawdata[3] = 0x4;
rawdata[4] = 0x5;
dc.addData(rawdata, LENGTH);
CPPUNIT_ASSERT(dc.at(0) == 0x1);
CPPUNIT_ASSERT(dc.at(1) == 0x2);
CPPUNIT_ASSERT(dc.at(2) == 0x3);
CPPUNIT_ASSERT(dc.at(3) == 0x4);
CPPUNIT_ASSERT(dc.at(4) == 0x5);
}
void DataChunkTest::test2_createFromExistingHeap()
{
int LENGTH = 5;
unsigned char *rawdata = new unsigned char(LENGTH);
rawdata[0] = 0x1;
rawdata[1] = 0x2;
rawdata[2] = 0x3;
rawdata[3] = 0x4;
rawdata[4] = 0x5;
DataChunk dc(&rawdata, LENGTH);
unsigned char *retdata = dc.getDataPointer();
CPPUNIT_ASSERT(retdata[0] == 0x1);
CPPUNIT_ASSERT(retdata[1] == 0x2);
CPPUNIT_ASSERT(retdata[2] == 0x3);
CPPUNIT_ASSERT(retdata[3] == 0x4);
CPPUNIT_ASSERT(retdata[4] == 0x5);
}
void DataChunkTest::test3_vectorReturn()
{
DataChunk dc;
int LENGTH = 5;
unsigned char rawdata[LENGTH];
rawdata[0] = 0x1;
rawdata[1] = 0x2;
rawdata[2] = 0x3;
rawdata[3] = 0x4;
rawdata[4] = 0x5;
dc.addData(rawdata, LENGTH);
std::vector<unsigned char> datavec = dc.getUCharVector();
CPPUNIT_ASSERT(datavec.at(0) == 0x1);
CPPUNIT_ASSERT(datavec.at(1) == 0x2);
CPPUNIT_ASSERT(datavec.at(2) == 0x3);
CPPUNIT_ASSERT(datavec.at(3) == 0x4);
CPPUNIT_ASSERT(datavec.at(4) == 0x5);
}
void DataChunkTest::test4_write_compare()
{
DataChunk dc;
int LENGTH = 5;
string savename = "datachunk.txt";
unsigned char rawdata[LENGTH];
rawdata[0] = 0x1;
rawdata[1] = 0x2;
rawdata[2] = 0x3;
rawdata[3] = 0x4;
rawdata[4] = 0x5;
dc.addData(rawdata, LENGTH);
dc.write(savename);
string line;
string filecontent;
ifstream readfile(savename);
if (readfile.is_open())
{
while (getline(readfile, line))
{
filecontent += line;
}
readfile.close();
}
CPPUNIT_ASSERT(filecontent.at(0) == 0x1);
CPPUNIT_ASSERT(filecontent.at(1) == 0x2);
CPPUNIT_ASSERT(filecontent.at(2) == 0x3);
CPPUNIT_ASSERT(filecontent.at(3) == 0x4);
CPPUNIT_ASSERT(filecontent.at(4) == 0x5);
fs::remove(savename);
}
void DataChunkTest::test5_read_write_compare()
{
DataChunk dc;
int LENGTH = 5;
string savename = "datachunk.txt";
unsigned char rawdata[LENGTH];
rawdata[0] = 0x1;
rawdata[1] = 0x2;
rawdata[2] = 0x3;
rawdata[3] = 0x4;
rawdata[4] = 0x5;
dc.addData(rawdata, LENGTH);
dc.write(savename);
string line;
string filecontent;
DataChunk dc_read;
dc_read.read(savename);
CPPUNIT_ASSERT(dc_read.at(0) == rawdata[0]);
CPPUNIT_ASSERT(dc_read.at(1) == rawdata[1]);
CPPUNIT_ASSERT(dc_read.at(2) == rawdata[2]);
CPPUNIT_ASSERT(dc_read.at(3) == rawdata[3]);
CPPUNIT_ASSERT(dc_read.at(4) == rawdata[4]);
fs::remove(savename);
}
| 3,099
|
C++
|
.cpp
| 122
| 22.483607
| 59
| 0.686288
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,080
|
TestHelpers.cpp
|
Wargus_stargus/test/module/TestHelpers.cpp
|
/*
* TestHelpers.cpp
*
* Author: Andreas Volz
*/
// project
#include "TestHelpers.h"
#include "FileUtil.h"
// system
#include <cstdio>
#include <fstream>
using namespace std;
const std::string getStringFromFile(const std::string &file)
{
string line;
string filecontent;
ifstream readfile(file);
if (readfile.is_open())
{
while (getline(readfile, line))
{
filecontent += line;
}
readfile.close();
}
return filecontent;
}
bool compareFiles(const std::string &file1, const std::string &file2)
{
if(!FileExists(file1) || !FileExists(file2))
{
return false;
}
string file1_content = getStringFromFile(file1);
string file2_content = getStringFromFile(file2);
if(file1_content.length() != file2_content.length())
{
return false;
}
else
{
const int ret = std::memcmp(file1_content.c_str(), file2_content.c_str(), file1_content.length());
if(ret != 0)
{
return false;
}
}
return true;
}
| 998
|
C++
|
.cpp
| 49
| 17.040816
| 104
| 0.671991
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,081
|
luagenTest.cpp
|
Wargus_stargus/test/module/luagenTest.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// system
#include <string>
// project
#include "luagenTest.h"
#include "luagen.h"
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(luagenTest);
void luagenTest::setUp()
{
}
void luagenTest::tearDown()
{
}
void luagenTest::test_function()
{
string string_function = lg::function("name", "one, two, three");
string initializer_list_function = lg::function("name", {"one", "two", "three"});
string lua_result_spec("name(one, two, three)");
CPPUNIT_ASSERT(initializer_list_function == lua_result_spec);
CPPUNIT_ASSERT(initializer_list_function == string_function);
}
void luagenTest::test_table()
{
string string_table = lg::table("one, two, three");
string initializer_list_table = lg::table({"one", "two", "three"});
string lua_result_spec("{one, two, three}");
CPPUNIT_ASSERT(string_table == lua_result_spec);
CPPUNIT_ASSERT(initializer_list_table == lua_result_spec);
}
void luagenTest::test_assign()
{
string result = lg::assign("a", "b");
CPPUNIT_ASSERT(result == "a = b");
}
void luagenTest::test_quote()
{
string result = lg::quote("example");
CPPUNIT_ASSERT(result == "\"example\"");
}
void luagenTest::test_singleQuote()
{
string result = lg::singleQuote("example");
CPPUNIT_ASSERT(result == "'example'");
}
void luagenTest::test_params()
{
vector<string> vector_params_input;
vector_params_input.push_back("one");
vector_params_input.push_back("two");
vector_params_input.push_back("three");
string intitializer_list_params = lg::params({"one", "two", "three"});
string vector_params = lg::params(vector_params_input);
string lua_result_spec("one, two, three");
CPPUNIT_ASSERT(intitializer_list_params == lua_result_spec);
CPPUNIT_ASSERT(vector_params == lua_result_spec);
}
void luagenTest::test_paramsQuote()
{
vector<string> vector_params_input;
vector_params_input.push_back("one");
vector_params_input.push_back("two");
vector_params_input.push_back("three");
string intitializer_list_params = lg::paramsQuote({"one", "two", "three"});
string vector_params = lg::paramsQuote(vector_params_input);
string lua_result_spec("\"one\", \"two\", \"three\"");
CPPUNIT_ASSERT(intitializer_list_params == lua_result_spec);
CPPUNIT_ASSERT(vector_params == lua_result_spec);
}
void luagenTest::test_line()
{
string result = lg::line("example");
CPPUNIT_ASSERT(result == "example\n");
}
| 2,443
|
C++
|
.cpp
| 76
| 29.776316
| 83
| 0.715203
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,082
|
StormTest.cpp
|
Wargus_stargus/test/module/StormTest.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// System
#include <zlib.h>
// Project
#include "StormTest.h"
#include "platform.h"
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(StormTest);
void StormTest::setUp()
{
}
void StormTest::tearDown()
{
}
void StormTest::test1_mpq_txt_extractMemory()
{
unsigned char *text_str = NULL;
size_t bufLen = 0;
string test_data_dir = "test/module/data/";
string content_result = "stormtest";
string mpq_arc_file = "test.txt";
shared_ptr<Storm> storm = make_shared<Storm>(test_data_dir + "StormTest_test1_mpq_txt.mpq");
bool result = storm->extractMemory(mpq_arc_file, &text_str, &bufLen);
CPPUNIT_ASSERT(result == true);
CPPUNIT_ASSERT((int)bufLen == ((int)content_result.length() + 1)); // calculate +1 because the '\0' counts extra in the raw char* data
CPPUNIT_ASSERT(string((char *) text_str) != string(content_result));
free(text_str);
}
void StormTest::test2_mpq_txt_extractFile()
{
string test_data_dir = "test/module/data/";
string content_result = "stormtest";
string mpq_arc_file = "test.txt";
string savename = "test.txt";
shared_ptr<Storm> storm = make_shared<Storm>(test_data_dir + "StormTest_test1_mpq_txt.mpq");
bool result = storm->extractFile(mpq_arc_file, savename, false);
string line;
string filecontent;
ifstream readfile(savename);
if (readfile.is_open())
{
while (getline(readfile, line))
{
filecontent += line;
}
readfile.close();
}
CPPUNIT_ASSERT(result == true);
CPPUNIT_ASSERT(content_result == filecontent);
fs::remove(savename);
}
void StormTest::test3_mpq_txt_extractFileCompressed()
{
string test_data_dir = "test/module/data/";
string content_result = "stormtest";
string mpq_arc_file = "test.txt";
string savename = "test.txt.gz";
gzFile gzfile = nullptr;
shared_ptr<Storm> storm = make_shared<Storm>(test_data_dir + "StormTest_test1_mpq_txt.mpq");
bool result = storm->extractFile(mpq_arc_file, savename, true);
// read back & compare ->
gzfile = gzopen(savename.c_str(), "r");
int err;
int bytes_read;
int max_length = 1024;
unsigned char buffer[max_length];
bytes_read = gzread(gzfile, buffer, max_length - 1);
buffer[bytes_read] = '\0';
if (bytes_read < max_length - 1)
{
if (!gzeof(gzfile))
{
gzerror(gzfile, & err);
CPPUNIT_ASSERT(err);
}
}
std::string dest(buffer, buffer + bytes_read-1);
CPPUNIT_ASSERT(result == true);
CPPUNIT_ASSERT(content_result == dest);
fs::remove(savename);
}
| 2,540
|
C++
|
.cpp
| 83
| 27.542169
| 136
| 0.697694
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,083
|
PcxTest.cpp
|
Wargus_stargus/test/module/PcxTest.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// System
// Project
#include "PcxTest.h"
#include "platform.h"
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(PcxTest);
void PcxTest::setUp()
{
}
void PcxTest::tearDown()
{
}
void PcxTest::test1_SaveIndexedPalettePNG()
{
string test_data_dir = "test/module/data/";
string load_pcx_name = "PcxTest_red_zergb.pcx";
string save_pal_name = "red_zergb.pal";
string save_png_name = "red_zergb.png";
shared_ptr<Breeze> breeze = make_shared<Breeze>(test_data_dir);
Pcx pcx1(breeze, load_pcx_name);
pcx1.savePNG(save_png_name);
std::shared_ptr<Palette> pal = pcx1.getPalette();
pal->createDataChunk()->write(save_pal_name);
CPPUNIT_ASSERT(compareFiles(save_pal_name, test_data_dir + "/PcxTest_" + save_pal_name));
CPPUNIT_ASSERT(compareFiles(save_png_name, test_data_dir + "/PcxTest_" + save_png_name));
fs::remove(save_pal_name.c_str());
fs::remove(save_png_name.c_str());
}
void PcxTest::test2_mapIndexPalette()
{
string test_data_dir = "test/module/data/";
string load_pcx_name = "PcxTest_ticon.pcx";
shared_ptr<Breeze> breeze = make_shared<Breeze>(test_data_dir);
Pcx pcx1(breeze);
for(unsigned int index = 0; index < 6; index++)
{
string save_pal_name = string("ticon_") + to_string(index) + ".pal";
string save_png_name = string("ticon_") + to_string(index) + ".png";
pcx1.load(load_pcx_name);
pcx1.savePNG(save_png_name);
std::shared_ptr<Palette> pal = pcx1.mapIndexPalette(8, 1, index);
pal->createDataChunk()->write(save_pal_name);
CPPUNIT_ASSERT(compareFiles(save_pal_name, test_data_dir + "/PcxTest_" + save_pal_name));
CPPUNIT_ASSERT(compareFiles(save_png_name, test_data_dir + "/PcxTest_" + save_png_name));
fs::remove(save_pal_name.c_str());
fs::remove(save_png_name.c_str());
}
}
| 1,843
|
C++
|
.cpp
| 51
| 33.137255
| 93
| 0.699435
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,084
|
TiledPaletteImageTest.cpp
|
Wargus_stargus/test/module/TiledPaletteImageTest.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// Project
#include "TiledPaletteImageTest.h"
#include "tileset/TiledPaletteImage.h"
#include "PngExporter.h"
#include "TestHelpers.h"
#include "platform.h"
// System
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(TiledPaletteImageTest);
void TiledPaletteImageTest::setUp()
{
}
void TiledPaletteImageTest::tearDown()
{
}
void TiledPaletteImageTest::test1_tileStrategyCompare()
{
string test_data_dir = "test/module/data/";
string reference_small_name_png = "TiledPaletteImage_small.png";
string save_num_name_png = "test1_tileStrategyCompare_num.png";
string save_pos_name_png = "test1_tileStrategyCompare_pos.png";
Palette pal(generateTestPalette());
PaletteImage red_image(Size(8, 8));
red_image.fill(ColorRed);
PaletteImage green_image(Size(8, 8));
green_image.fill(ColorGreen);
PaletteImage blue_image(Size(8, 8));
blue_image.fill(ColorBlue);
PaletteImage yellow_image(Size(8, 8));
yellow_image.fill(ColorYellow);
tileset::TiledPaletteImage tiled_image_num(Size(2, 2), Size(8, 8));
tileset::TiledPaletteImage tiled_image_pos(Size(2, 2), Size(8, 8));
// fill the tiled image with the little tiles by incrementing number
tiled_image_num.copyTile(red_image, 0);
tiled_image_num.copyTile(green_image, 1);
tiled_image_num.copyTile(blue_image, 2);
tiled_image_num.copyTile(yellow_image, 3);
// fill the tiled image with the little tiles by specifying the tile position
tiled_image_pos.copyTile(red_image, Pos(0, 0));
tiled_image_pos.copyTile(green_image, Pos(1, 0));
tiled_image_pos.copyTile(blue_image, Pos(0, 1));
tiled_image_pos.copyTile(yellow_image, Pos(1, 1));
// export the PNGs for visual test feedback
PngExporter::saveRGB(save_num_name_png, tiled_image_num, pal, 255);
PngExporter::saveRGB(save_pos_name_png, tiled_image_pos, pal, 255);
// this test just checks if adding the tiles by #num or Pos gives us the same result
CPPUNIT_ASSERT(tiled_image_num == tiled_image_pos);
CPPUNIT_ASSERT(compareFiles(save_num_name_png, test_data_dir + "/" + reference_small_name_png));
CPPUNIT_ASSERT(compareFiles(save_pos_name_png, test_data_dir + "/" + reference_small_name_png));
// TODO: save both vectors into file and compare them with a working result!
// maybe as other additional test??
fs::remove(save_num_name_png);
fs::remove(save_pos_name_png);
}
void TiledPaletteImageTest::test2_tileHorizontalFlipping()
{
string test_data_dir = "test/module/data/";
string reference_big_flipped_name_png = "TiledPaletteImageTest2_big_flipped.png";
string save_name_flipped_png = "test2_tileHorizontalFlipping.png";
Palette pal(generateTestPalette());
PaletteImage red_image(Size(8, 8));
red_image.fill(ColorRed);
PaletteImage green_image(Size(8, 8));
green_image.fill(ColorGreen);
PaletteImage blue_image(Size(8, 8));
blue_image.fill(ColorBlue);
PaletteImage yellow_image(Size(8, 8));
yellow_image.fill(ColorYellow);
tileset::TiledPaletteImage tiled_image_num(Size(2, 2), Size(8, 8));
// fill the tiled image with the little tiles by incrementing number
tiled_image_num.copyTile(red_image, 0);
tiled_image_num.copyTile(green_image, 1);
tiled_image_num.copyTile(blue_image, 2);
tiled_image_num.copyTile(yellow_image, 3);
tileset::TiledPaletteImage tiled_image_big(Size(2, 2), Size(16, 16));
tiled_image_big.copyTile(tiled_image_num, 0, true); // flip horizontal
tiled_image_big.copyTile(tiled_image_num, 1);
tiled_image_big.copyTile(tiled_image_num, 2, true); // flip horizontal
tiled_image_big.copyTile(tiled_image_num, 3);
PngExporter::saveRGB(save_name_flipped_png, tiled_image_big, pal, 255);
CPPUNIT_ASSERT(compareFiles(save_name_flipped_png, test_data_dir + "/" + reference_big_flipped_name_png));
fs::remove(save_name_flipped_png);
}
Palette TiledPaletteImageTest::generateTestPalette()
{
Palette pal;
// define the colors
Color black(0, 0, 0);
Color red(255, 0, 0);
Color green(0, 255, 0);
Color blue(0, 0, 255);
Color yellow(255, 255, 0);
// add the colors in the palette
pal.at(0) = black;
pal.at(1) = red;
pal.at(2) = green;
pal.at(3) = blue;
pal.at(4) = yellow;
return pal;
}
| 4,226
|
C++
|
.cpp
| 103
| 38.15534
| 108
| 0.742773
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,085
|
BreezeTest.cpp
|
Wargus_stargus/test/module/BreezeTest.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// System
#include <zlib.h>
// Project
#include "BreezeTest.h"
#include "platform.h"
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(BreezeTest);
void BreezeTest::setUp()
{
}
void BreezeTest::tearDown()
{
}
void BreezeTest::test1_txt_extractMemory()
{
unsigned char *text_str = NULL;
size_t bufLen = 0;
string test_data_dir = "test/module/data/";
string content_result = "breezetest";
string arc_file = "breezetest.txt";
shared_ptr<Breeze> breeze = make_shared<Breeze>(test_data_dir);
bool result = breeze->extractMemory(arc_file, &text_str, &bufLen);
CPPUNIT_ASSERT(result == true);
CPPUNIT_ASSERT((int)bufLen == ((int)content_result.length() + 1)); // calculate +1 because the '\0' counts extra in the raw char* data
CPPUNIT_ASSERT(string((char *) text_str) != string(content_result));
CPPUNIT_ASSERT(true);
}
void BreezeTest::test2_txt_extractFile()
{
string test_data_dir = "test/module/data/";
string content_result = "breezetest";
string arc_file = "breezetest.txt";
string savename = "breezetest_test.txt";
shared_ptr<Breeze> breeze = make_shared<Breeze>(test_data_dir);
bool result = breeze->extractFile(arc_file, savename, false);
string line;
string filecontent;
ifstream readfile(savename);
if (readfile.is_open())
{
while (getline(readfile, line))
{
filecontent += line;
}
readfile.close();
}
CPPUNIT_ASSERT(result == true);
CPPUNIT_ASSERT(content_result == filecontent);
fs::remove(savename);
}
void BreezeTest::test3_txt_extractFileCompressed()
{
string test_data_dir = "test/module/data/";
string content_result = "breezetest";
string arc_file = "breezetest.txt";
string savename = "test.txt.gz";
gzFile gzfile = nullptr;
shared_ptr<Breeze> breeze = make_shared<Breeze>(test_data_dir);
bool result = breeze->extractFile(arc_file, savename, true);
// read back & compare ->
gzfile = gzopen(savename.c_str(), "r");
int err;
int bytes_read;
int max_length = 1024;
unsigned char buffer[max_length];
bytes_read = gzread(gzfile, buffer, max_length - 1);
buffer[bytes_read] = '\0';
if (bytes_read < max_length - 1)
{
if (!gzeof(gzfile))
{
gzerror(gzfile, & err);
CPPUNIT_ASSERT(err);
}
}
std::string dest(buffer, buffer + bytes_read-1);
CPPUNIT_ASSERT(result == true);
CPPUNIT_ASSERT(content_result == dest);
fs::remove(savename);
}
| 2,465
|
C++
|
.cpp
| 83
| 26.638554
| 136
| 0.702932
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,086
|
unit_dat.cpp
|
Wargus_stargus/tools/unit_dat.cpp
|
const char ** WeaponTypes = {"unknown", "explosive", "concussive", "normal", "spell"};
#pragma pack(1)
struct WeaponType
{
unsigned short label;
unsigned short sprite;
unsigned short spell;
unsigned short flag;
unsigned short range;
unsigned short upgrade_type;
unsigned short type;
unsigned short mbehavior;
unsigned short mtype;
unsigned short explosion;
unsigned short splash;
unsigned short damage;
unsigned short bonus;
unsigned short cool;
unsigned short factor;
unsigned short pos1;
unsigned short pos2;
unsigned short msg;
unsigned short icon;
};
#pragma pop()
| 617
|
C++
|
.cpp
| 25
| 21.76
| 87
| 0.761986
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
752,087
|
json_transition.cpp
|
Wargus_stargus/tools/json_transition.cpp
|
/*
* json_transition.cpp
*
* This is just a temporary tool for transition of the old array style data to json
*
* Author: Andreas Volz
*/
#include <nlohmann/json.hpp>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <fstream>
#include "../src/startool_mpq.h"
using namespace std;
using json = nlohmann::json;
extern const char *UnitNames[];
struct Unit
{
string name;
int id;
};
string getTypeName(int type)
{
string str;
switch (type)
{
case S: // Setup
str = "S";
break;
case F: // File (name)
str = "F";
break;
case M: // Map (name)
str = "M";
break;
case T: // Tileset (name,pal,mega,mini,map)
str = "T";
break;
case R: // RGB -> gimp (name,rgb)
str = "R";
break;
case G: // Graphics (name,pal,gfx)
str = "G";
break;
case U: // Uncompressed Graphics (name,pal,gfu)
str = "U";
break;
case I: // Widgets (name,pal,gfu)
str = "I";
break;
case N: // Font (name,idx)
str = "N";
break;
case W: // Wav (name,wav)
str = "W";
break;
case H: // Pcx (name)
str = "W";
break;
case E: // Raw extract (name)
str = "E";
break;
case V: // SMK Video (name,video)
str = "V";
break;
case L: // Campaign Levels
str = "L";
break;
case Q: // MPQ archive
str = "Q";
break;
case D: // Graphics in DDS format
str = "D";
break;
case P: // SMK Portraits
str = "P";
break;
case PAL: // Palette from pcx file
str = "PAL";
break;
case WPE: // Palette from wpe file
str = "WPE";
break;
default:
break;
}
return str;
}
void to_json(json &j, const Control &c)
{
j = json{ {"type", getTypeName(c.Type)}, {"file", c.File}, {"arcfile", c.ArcFile} };
}
void to_json(json &j, const Unit &u)
{
j = json{ {"name", u.name}, {"id", u.id} };
}
void Unit_Array_Creator()
{
for(unsigned int un = 0; un < 228; un++)
{
printf("unit %d: %s\n", un, UnitNames[un]);
}
}
void Todo_creator()
{
Control *c = nullptr;
unsigned int len = 0;
c = Todo_bootstrap;
len = sizeof(Todo_bootstrap) / sizeof(*Todo_bootstrap);
for (unsigned int u = 0; u < len; ++u)
{
switch (c[u].Type)
{
case F:
{
}
break;
default:
break;
}
}
c = Todo_bootstrap;
len = sizeof(Todo_bootstrap) / sizeof(*Todo_bootstrap);
for (unsigned int u = 0; u < len; ++u)
{
switch (c[u].Type)
{
case F:
{
}
break;
default:
break;
}
}
json j;
for (unsigned int i = 0; i <= 1; ++i)
{
switch (i)
{
case 0:
// StarDat.mpq or stardat.mpq from inside files\\stardat.mpq
c = Todo;
len = sizeof(Todo) / sizeof(*Todo);
break;
case 1:
// CD install.exe renamed to StarCraft.mpq or other main mpq file
c = CDTodo;
len = sizeof(CDTodo) / sizeof(*CDTodo);
break;
}
for (unsigned int u = 0; u < len; ++u)
{
j["object" + to_string(u)] = c[u];
/* j["type"] = c[u].Type;
j["file"] = c[u].File;
j["arcfile"] = c[u].ArcFile;
j["Arg1"] = c[u].Arg1;
j["Arg2"] = c[u].Arg2;
j["Arg3"] = c[u].Arg3;
j["Arg4"] = c[u].Arg4;
*/
switch (c[u].Type)
{
case PAL:
{
break;
}
}
}
}
cout << std::setw(4) << j << endl;
}
void Unit_File_Creator(string filename)
{
json j;
ifstream input_file(filename);
std::string line;
int i = 0;
while (std::getline(input_file, line))
{
//cout << line << endl;
std::for_each(line.begin(), line.end(), [](char & c)
{
c = ::tolower(c);
});
Unit u;
u.name = "unit-" + line;
u.id = i;
j[i] = u;
i++;
}
cout << std::setw(4) << j << endl;
}
int main(int argc, char **argv)
{
//Unit_File_Creator("..b/data/units.txt");
//Unit_Array_Creator();
Todo_creator();
return 0;
}
const char *UnitNames[] =
{
"unit-terran-marine", "unit-terran-ghost", "unit-terran-vulture",
"unit-terran-goliath", "Goliath-Turret",
"unit-terran-siege-tank-(Tank-Mode)", "Tank-Turret(Tank-Mode)",
"unit-terran-scv", "unit-terran-wraith", "unit-terran-science-vessel",
"Gui-Montang-(Firebat)", "unit-terran-dropship",
"unit-terran-battlecruiser", "Vulture-Spider-Mine", "Nuclear-Missile",
"unit-terran-civilian", "Sarah-Kerrigan-(Ghost)", "Alan-Schezar-(Goliath)",
"Alan-Schezar-Turret", "Jim-Raynor-(Vulture)", "Jim-Raynor-(Marine)",
"Tom-Kazansky-(Wraith)", "Magellan-(Science-Vessel)",
"Edmund-Duke-(Siege-Tank)", "Edmund-Duke-Turret",
"Edmund-Duke-(Siege-Mode)", "Edmund-Duke-Turret",
"Arcturus-Mengsk-(Battlecruiser)", "Hyperion-(Battlecruiser)",
"Norad-II-(Battlecruiser)", "unit-terran-siege-tank-(Siege-Mode)",
"Tank-Turret-(Siege-Mode)", "Firebat", "Scanner-Sweep", "unit-terran-medic",
"unit-zerg-larva", "unit-zerg-egg", "unit-zerg-zergling",
"unit-zerg-hydralisk", "unit-zerg-ultralisk", "unit-zerg-broodling",
"unit-zerg-drone", "unit-zerg-overlord", "unit-zerg-mutalisk",
"unit-zerg-guardian", "unit-zerg-queen", "unit-zerg-defiler",
"unit-zerg-scourge", "Torrarsque-(Ultralisk)", "Matriarch-(Queen)",
"Infested-Terran", "Infested-Kerrigan", "Unclean-One-(Defiler)",
"Hunter-Killer-(Hydralisk)", "Devouring-One-(Zergling)",
"Kukulza-(Mutalisk)", "Kukulza-(Guardian)", "Yggdrasill-(Overlord)",
"unit-terran-valkyrie-frigate", "Mutalisk/Guardian-Cocoon",
"unit-protoss-corsair", "unit-protoss-dark-templar(Unit)",
"unit-zerg-devourer", "unit-protoss-dark-archon", "unit-protoss-probe",
"unit-protoss-zealot", "unit-protoss-dragoon", "unit-protoss-high-templar",
"unit-protoss-archon", "unit-protoss-shuttle", "unit-protoss-scout",
"unit-protoss-arbiter", "unit-protoss-carrier", "unit-protoss-interceptor",
"Dark-Templar(Hero)", "Zeratul-(Dark-Templar)", "Tassadar/Zeratul-(Archon)",
"Fenix-(Zealot)", "Fenix-(Dragoon)", "Tassadar-(Templar)", "Mojo-(Scout)",
"Warbringer-(Reaver)", "Gantrithor-(Carrier)", "unit-protoss-reaver",
"unit-protoss-observer", "unit-protoss-scarab", "Danimoth-(Arbiter)",
"Aldaris-(Templar)", "Artanis-(Scout)", "Rhynadon-(Badlands-Critter)",
"Bengalaas-(Jungle-Critter)", "Unused---Was-Cargo-Ship",
"Unused---Was-Mercenary-Gunship", "Scantid-(Desert-Critter)",
"Kakaru-(Twilight-Critter)", "Ragnasaur-(Ashworld-Critter)",
"Ursadon-(Ice-World-Critter)", "Lurker-Egg", "Raszagal",
"Samir-Duran-(Ghost)", "Alexei-Stukov-(Ghost)", "Map-Revealer",
"Gerard-DuGalle", "unit-zerg-Lurker", "Infested-Duran", "Disruption-Web",
"unit-terran-command-center", "unit-terran-comsat-station",
"unit-terran-nuclear-silo", "unit-terran-supply-depot",
"unit-terran-refinery", "unit-terran-barracks", "unit-terran-academy",
"unit-terran-factory", "unit-terran-starport", "unit-terran-control-tower",
"unit-terran-science-facility", "unit-terran-covert-ops",
"unit-terran-physics-lab", "Unused---Was-Starbase?",
"unit-terran-machine-shop", "Unused---Was-Repair-Bay?",
"unit-terran-engineering-bay", "unit-terran-armory",
"unit-terran-missile-turret", "unit-terran-bunker", "Norad-II",
"Ion-Cannon", "Uraj-Crystal", "Khalis-Crystal", "Infested-Command-Center",
"unit-zerg-hatchery", "unit-zerg-lair", "unit-zerg-hive",
"unit-zerg-nydus-canal", "unit-zerg-hydralisk-den",
"unit-zerg-defiler-mound", "unit-zerg-greater-spire",
"unit-zerg-queens-nest", "unit-zerg-evolution-chamber",
"unit-zerg-ultralisk-cavern", "unit-zerg-spire", "unit-zerg-spawning-pool",
"unit-zerg-creep-colony", "unit-zerg-spore-colony", "Unused-Zerg-Building",
"unit-zerg-sunken-colony", "unit-zerg-overmind-(With-Shell)",
"unit-zerg-overmind", "unit-zerg-extractor", "Mature-Chrysalis",
"unit-zerg-cerebrate", "unit-zerg-cerebrate-daggoth",
"Unused-Zerg-Building-5", "unit-protoss-nexus",
"unit-protoss-robotics-facility", "unit-protoss-pylon",
"unit-protoss-assimilator", "Unused-Protoss-Building",
"unit-protoss-observatory", "unit-protoss-gateway",
"Unused-Protoss-Building", "unit-protoss-photon-cannon",
"unit-protoss-citadel-of-adun", "unit-protoss-cybernetics-core",
"unit-protoss-templar-archives", "unit-protoss-forge",
"unit-protoss-stargate", "Stasis-Cell/Prison", "unit-protoss-fleet-beacon",
"unit-protoss-arbiter-tribunal", "unit-protoss-robotics-support-bay",
"unit-protoss-shield-battery", "Khaydarin-Crystal-Formation",
"unit-protoss-temple", "Xel'Naga-Temple", "unit-minerals1",
"unit-minerals2", "unit-minerals3", "Cave", "Cave-in", "Cantina",
"Mining-Platform", "Independant-Command-Center", "Independant-Starport",
"Independant-Jump-Gate", "Ruins", "Kyadarin-Crystal-Formation",
"unit-vespene-geyser", "Warp-Gate", "PSI-Disruptor", "unit-zerg-marker",
"unit-terran-marker", "unit-protoss-marker", "unit-zerg-beacon",
"unit-terran-beacon", "unit-protoss-beacon", "unit-zerg-flag-beacon",
"unit-terran-flag-beacon", "unit-protoss-flag-beacon", "Power-Generator",
"Overmind-Cocoon", "Dark-Swarm", "Floor-Missile-Trap", "Floor-Hatch",
"Left-Upper-Level-Door", "Right-Upper-Level-Door", "Left-Pit-Door",
"Right-Pit-Door", "Floor-Gun-Trap", "Left-Wall-Missile-Trap",
"Left-Wall-Flame-Trap", "Right-Wall-Missile-Trap", "Right-Wall-Flame-Trap",
"Start-Location", "Flag", "Young-Chrysalis", "Psi-Emitter", "Data-Disc",
"Khaydarin-Crystal", "Mineral-Cluster-Type-1", "Mineral-Cluster-Type-2",
"unit-protoss-vespene-gas-orb-type-1",
"unit-protoss-vespene-gas-orb-type-2", "unit-zerg-vespene-gas-sac-type-1",
"unit-zerg-vespene-gas-sac-type-2", "unit-terran-vespene-gas-tank-type-1",
"unit-terran-vespene-gas-tank-type-2",
};
| 9,988
|
C++
|
.cpp
| 292
| 30.417808
| 86
| 0.627148
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,088
|
sauwetter.cpp
|
Wargus_stargus/tools/sauwetter/sauwetter.cpp
|
/*
* sauwetter.cpp
*
* Author: Andreas Volz
*/
// project
#include "Breeze.h"
#include "Storm.h"
#include "Casc.h"
#include "FileUtil.h"
#include "StringUtil.h"
#include "optparser.h"
// system
#include <iostream>
using namespace std;
// some global variables
string backend;
string archive;
string archive_file;
string destination_directory;
bool CheckCASCDataFolder(const std::string &dir)
{
return FileExists(dir + "/.build.info");
}
/** option parser **/
struct Arg: public option::Arg
{
static void printError(const char *msg1, const option::Option &opt, const char *msg2)
{
fprintf(stderr, "%s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(const option::Option &option, bool msg)
{
if (msg)
printError("Unknown option '", option, "'\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(const option::Option &option, bool msg)
{
if (option.arg != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires an argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus NonEmpty(const option::Option &option, bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a non-empty argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(const option::Option &option, bool msg)
{
char *endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10))
{
};
if (endptr != option.arg && *endptr == 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a numeric argument\n");
return option::ARG_ILLEGAL;
}
};
enum optionIndex
{
UNKNOWN, HELP, BACKEND
};
const option::Descriptor usage[] =
{
{
UNKNOWN, 0, "", "", option::Arg::None, "USAGE: sauwetter archive [options] archive-file destination-directory\n\n"
"Options:"
},
{ HELP, 0, "h", "help", option::Arg::None, " --help, -h \t\tPrint usage and exit" },
{ BACKEND, 0, "b", "backend", Arg::Required, " --backend BACKEND, -b BACKEND \t\tChoose a backend (Storm=St*arcr*ft1/Br**dwar;Casc=Remastered;Breeze=Folder)" },
{
UNKNOWN, 0, "", "", option::Arg::None,
"\narchive \t\tDestination to the archive (mpq, casc or dummy folder) based on backend.\n"
"\narchive-file \t\tThe file inside the archive (with relative path) that is to be extracted.\n"
"\ndestination-directory \t\tWhere to save the extracted file with same relative path.\n"
},
{ 0, 0, 0, 0, 0, 0 }
};
int parseOptions(int argc, const char **argv)
{
argc -= (argc > 0);
argv += (argc > 0); // skip program name argv[0] if present
option::Stats stats(usage, argc, argv);
std::unique_ptr<option::Option[]> options(new option::Option[stats.options_max]), buffer(new option::Option[stats.buffer_max]);
option::Parser parse(usage, argc, argv, options.get(), buffer.get());
if (parse.error())
exit(0);
if (options[HELP])
{
option::printUsage(std::cout, usage);
exit(0);
}
if(options[BACKEND].count() > 0)
{
backend = options[BACKEND].arg;
}
else
{
cerr << "Error: 'backend' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
// parse options
for (option::Option *opt = options[UNKNOWN]; opt; opt = opt->next())
std::cout << "Unknown option: " << opt->name << "\n";
for (int i = 0; i < parse.nonOptionsCount(); ++i)
{
switch (i)
{
case 0:
//cerr << "archive #" << i << ": " << parse.nonOption(i) << "\n";
archive = parse.nonOption(i);
break;
case 1:
//cerr << "archive-file #" << i << ": " << parse.nonOption(i) << "\n";
archive_file = parse.nonOption(i);
break;
case 2:
//cerr << "destination-directory #" << i << ": " << parse.nonOption(i) << "\n";
destination_directory = parse.nonOption(i);
break;
default:
break;
}
}
if (archive.empty())
{
cerr << "Error: 'archive' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
if (archive_file.empty())
{
cerr << "Error: 'archive_file' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
if (destination_directory.empty())
{
cerr << "Error: 'destination_directory' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
return 0;
}
int main(int argc, const char **argv)
{
parseOptions(argc, argv);
bool archive_exists = FileExists(archive);
if(!archive_exists)
{
cerr << "archive not existing - exit!" << endl;
exit(1);
}
shared_ptr<Hurricane> hurricane;
cerr << "Backend: " << backend << endl;
if(to_lower(backend) == "breeze")
{
hurricane = make_shared<Breeze>(archive);
}
else if(to_lower(backend) == "storm")
{
hurricane = make_shared<Storm>(archive);
}
else if(to_lower(backend) == "casc")
{
#ifdef HAVE_CASC
if(CheckCASCDataFolder(archive))
{
hurricane = make_shared<Casc>(archive);
}
else
{
cerr << "Error: 'archive' is not a CASC archive!" << endl;
}
#else
cerr << "Error: No CASC support compiled into sauwetter!" << endl;
exit(1);
#endif
}
string archive_file_slash(archive_file);
replaceString("\\", "/", archive_file_slash);
string destination_full_path = destination_directory + "/" + archive_file_slash;
bool result = hurricane->extractFile(archive_file, destination_full_path, false);
printf("extracted %s ... %s\n", destination_full_path.c_str(), result ? "ok" : "nok");
return !result;
}
| 5,745
|
C++
|
.cpp
| 197
| 25.385787
| 164
| 0.634368
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,089
|
SCJsonExporter.cpp
|
Wargus_stargus/tools/scdat2json/SCJsonExporter.cpp
|
/*
* SCJsonExporter.cpp
*
* Author: Andreas Volz
*/
// project
#include "SCJsonExporter.h"
#include "to_json.h"
// system
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
using namespace dat;
SCJsonExporter::SCJsonExporter(dat::DataHub &datahub) :
mDatahub(datahub)
{
}
SCJsonExporter::~SCJsonExporter()
{
}
json SCJsonExporter::export_unit_dat()
{
// TODO: check if to_json() method for units_dat_t is good
std::shared_ptr<units_dat_t> units = mDatahub.units;
json j;
j["flingy"] = json(*units->flingy());
j["subunit1"] = json(*units->subunit1());
j["subunit2"] = json(*units->subunit2());
j["infestation"] = json(*units->infestation());
j["construction_animation"] = json(*units->construction_animation());
j["unit_direction"] = json(*units->unit_direction());
j["shield_enable"] = json(*units->shield_enable());
j["shield_amount"] = json(*units->shield_amount());
j["hit_points"] = json(*units->hit_points());
j["elevation_level"] = json(*units->elevation_level());
j["unknown"] = json(*units->unknown());
j["rank"] = json(*units->rank());
j["ai_computer_idle"] = json(*units->ai_computer_idle());
j["ai_human_idle"] = json(*units->ai_human_idle());
j["ai_return_to_idle"] = json(*units->ai_return_to_idle());
j["ai_attack_unit"] = json(*units->ai_attack_unit());
j["ai_attack_move"] = json(*units->ai_attack_move());
j["ground_weapon"] = json(*units->ground_weapon());
if(units->is_format_bw())
{
j["max_ground_hits"] = json(*units->max_ground_hits());
}
j["air_weapon"] = json(*units->air_weapon());
if(units->is_format_bw())
{
j["max_air_hits"] = json(*units->max_air_hits());
}
j["ai_internal"] = json(*units->ai_internal());
j["special_ability_flags"] = json(*units->special_ability_flags());
j["target_acquisition_range"] = json(*units->target_acquisition_range());
j["sight_range"] = json(*units->sight_range());
j["armor_upgrade"] = json(*units->armor_upgrade());
j["unit_size"] = json(*units->unit_size());
j["armor"] = json(*units->armor());
j["right_click_action"] = json(*units->right_click_action());
j["ready_sound"] = json(*units->ready_sound());
j["what_sound_start"] = json(*units->what_sound_start());
j["what_sound_end"] = json(*units->what_sound_end());
j["piss_sound_start"] = json(*units->piss_sound_start());
j["piss_sound_end"] = json(*units->piss_sound_end());
j["yes_sound_start"] = json(*units->yes_sound_start());
j["yes_sound_end"] = json(*units->yes_sound_end());
j["staredit_placement_box"] = json(*units->staredit_placement_box());
j["addon_position"] = json(*units->addon_position());
j["unit_dimension"] = json(*units->unit_dimension());
j["portrait"] = json(*units->portrait());
j["mineral_cost"] = json(*units->mineral_cost());
j["vespene_cost"] = json(*units->vespene_cost());
j["build_time"] = json(*units->build_time());
j["requirements"] = json(*units->requirements());
j["staredit_group_flags"] = json(*units->staredit_group_flags());
j["supply_provided"] = json(*units->supply_provided());
j["supply_required"] = json(*units->supply_required());
j["space_required"] = json(*units->space_required());
j["space_provided"] = json(*units->space_provided());
j["build_score"] = json(*units->build_score());
j["destroy_score"] = json(*units->destroy_score());
j["unit_map_string"] = json(*units->unit_map_string());
if(units->is_format_bw())
{
j["broodwar_flag"] = json(*units->broodwar_flag());
}
j["staredit_availability_flags"] = json(*units->staredit_availability_flags());
return j;
}
json SCJsonExporter::export_orders_dat()
{
std::shared_ptr<orders_dat_t> orders = mDatahub.orders;
json j;
j["label"] = json(*orders->label());
j["use_weapon_targeting"] = json(*orders->use_weapon_targeting());
j["unknown2"] = json(*orders->unknown2());
j["unknown3"] = json(*orders->unknown3());
j["unknown4"] = json(*orders->unknown4());
j["unknown5"] = json(*orders->unknown5());
j["interruptible"] = json(*orders->interruptible());
j["unknown7"] = json(*orders->unknown7());
j["queueable"] = json(*orders->queueable());
j["unknown9"] = json(*orders->unknown9());
j["unknown10"] = json(*orders->unknown10());
j["unknown11"] = json(*orders->unknown11());
j["unknown12"] = json(*orders->unknown12());
j["targeting"] = json(*orders->targeting());
j["energy"] = json(*orders->energy());
j["animation"] = json(*orders->animation());
j["highlight"] = json(*orders->highlight());
j["unknown17"] = json(*orders->unknown17());
j["obscured_order"] = json(*orders->obscured_order());
return j;
}
json SCJsonExporter::export_weapons_dat()
{
std::shared_ptr<weapons_dat_t> weapons = mDatahub.weapons;
json j;
j["label"] = json(*weapons->label());
j["graphics"] = json(*weapons->graphics());
j["explosion"] = json(*weapons->explosion());
j["target_flags"] = json(*weapons->target_flags());
j["minimum_range"] = json(*weapons->minimum_range());
j["maximum_range"] = json(*weapons->maximum_range());
j["damage_upgrade"] = json(*weapons->damage_upgrade());
j["weapon_type"] = json(*weapons->weapon_type());
j["weapon_behaviour"] = json(*weapons->weapon_behaviour());
j["remove_after"] = json(*weapons->remove_after());
j["explosive_type"] = json(*weapons->explosive_type());
j["inner_splash_range"] = json(*weapons->inner_splash_range());
j["medium_splash_range"] = json(*weapons->medium_splash_range());
j["outer_splash_range"] = json(*weapons->outer_splash_range());
j["damage_amount"] = json(*weapons->damage_amount());
j["damage_bonus"] = json(*weapons->damage_bonus());
j["weapon_cooldown"] = json(*weapons->weapon_cooldown());
j["damage_factor"] = json(*weapons->damage_factor());
j["attack_angle"] = json(*weapons->attack_angle());
j["launch_spin"] = json(*weapons->launch_spin());
j["x_offset"] = json(*weapons->x_offset());
j["y_offset"] = json(*weapons->y_offset());
j["error_message"] = json(*weapons->error_message());
j["icon"] = json(*weapons->icon());
return j;
}
json SCJsonExporter::export_flingy_dat()
{
std::shared_ptr<flingy_dat_t> flingy = mDatahub.flingy;
json j;
j["sprite"] = json(*flingy->sprite());
j["speed"] = json(*flingy->speed());
j["acceleration"] = json(*flingy->acceleration());
j["halt_distance"] = json(*flingy->halt_distance());
j["turn_radius"] = json(*flingy->turn_radius());
j["unused"] = json(*flingy->unused());
j["movement_control"] = json(*flingy->movement_control());
return j;
}
json SCJsonExporter::export_sprites_dat()
{
std::shared_ptr<sprites_dat_t> sprites = mDatahub.sprites;
json j;
j["image"] = json(*sprites->image());
j["health_bar"] = json(*sprites->health_bar());
j["unknown2"] = json(*sprites->unknown2());
j["is_visible"] = json(*sprites->is_visible());
j["select_circle_image_size"] = json(*sprites->select_circle_image_size());
j["select_circle_vertical_pos"] = json(*sprites->select_circle_vertical_pos());
return j;
}
json SCJsonExporter::export_images_dat()
{
std::shared_ptr<images_dat_t> images = mDatahub.images;
json j;
j["grp"] = json(*images->grp());
j["gfx_turns"] = json(*images->gfx_turns());
j["clickable"] = json(*images->clickable());
j["use_full_iscript"] = json(*images->use_full_iscript());
j["draw_if_cloaked"] = json(*images->draw_if_cloaked());
j["draw_function"] = json(*images->draw_function());
j["remapping"] = json(*images->remapping());
j["iscript"] = json(*images->iscript());
j["shield_overlay"] = json(*images->shield_overlay());
j["attack_overlay"] = json(*images->attack_overlay());
j["damage_overlay"] = json(*images->damage_overlay());
j["special_overlay"] = json(*images->special_overlay());
j["landing_dust_overlay"] = json(*images->landing_dust_overlay());
j["lift_off_dust_overlay"] = json(*images->lift_off_dust_overlay());
return j;
}
json SCJsonExporter::export_sfxdata_dat()
{
std::shared_ptr<sfxdata_dat_t> sfxdata = mDatahub.sfxdata;
json j;
j["sound_file"] = json(*sfxdata->sound_file());
j["unknown1"] = json(*sfxdata->unknown1());
j["unknown2"] = json(*sfxdata->unknown2());
j["unknown3"] = json(*sfxdata->unknown3());
j["unknown4"] = json(*sfxdata->unknown4());
return j;
}
json SCJsonExporter::export_portdata_dat()
{
std::shared_ptr<portdata_dat_t> portdata = mDatahub.portdata;
json j;
j["video_idle"] = json(*portdata->video_idle());
j["video_talking"] = json(*portdata->video_talking());
j["change_idle"] = json(*portdata->change_idle());
j["unknown1_idle"] = json(*portdata->unknown1_idle());
j["unknown1_talking"] = json(*portdata->unknown1_talking());
return j;
}
json SCJsonExporter::export_upgrades_dat()
{
std::shared_ptr<upgrades_dat_t> upgrades = mDatahub.upgrades;
json j;
j["mineral_cost_base"] = json(*upgrades->mineral_cost_base());
j["mineral_cost_factor"] = json(*upgrades->mineral_cost_factor());
j["vespene_cost_base"] = json(*upgrades->vespene_cost_base());
j["vespene_cost_factor"] = json(*upgrades->vespene_cost_factor());
j["research_time_base"] = json(*upgrades->research_time_base());
j["research_time_factor"] = json(*upgrades->research_time_factor());
j["unknown6"] = json(*upgrades->unknown6());
j["icon"] = json(*upgrades->icon());
j["label"] = json(*upgrades->label());
j["race"] = json(*upgrades->race());
j["max_repeats"] = json(*upgrades->max_repeats());
if(upgrades->has_broodwar_flag())
{
j["broodwar_flags"] = json(*upgrades->broodwar_flags());
}
return j;
}
json SCJsonExporter::export_techdata_dat()
{
std::shared_ptr<techdata_dat_t> techdata = mDatahub.techdata;
json j;
j["mineral_cost"] = json(*techdata->mineral_cost());
j["vespene_cost"] = json(*techdata->vespene_cost());
j["research_time"] = json(*techdata->research_time());
j["energy_required"] = json(*techdata->energy_required());
j["unknown4"] = json(*techdata->unknown4());
j["icon"] = json(*techdata->icon());
j["label"] = json(*techdata->label());
j["race"] = json(*techdata->race());
j["unused"] = json(*techdata->unused());
if(techdata->has_broodwar_flag())
{
j["broodwar_flag"] = json(*techdata->broodwar_flag());
}
return j;
}
json SCJsonExporter::export_mapdata_dat()
{
std::shared_ptr<mapdata_dat_t> mapdata = mDatahub.mapdata;
json j;
j["mission_dir"] = json(*mapdata->mission_dir());
return j;
}
json SCJsonExporter::export_file_tbl(std::vector<TblEntry> &tblentry_vec)
{
json j(tblentry_vec);
return j;
}
| 10,713
|
C++
|
.cpp
| 265
| 37.033962
| 81
| 0.655866
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,090
|
UnitsJsonExporter.cpp
|
Wargus_stargus/tools/scdat2json/UnitsJsonExporter.cpp
|
/*
* UnitsJsonExporter.cpp
*
* Author: Andreas Volz
*/
// project
#include "UnitsJsonExporter.h"
#include "to_json.h"
// system
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
using namespace dat;
UnitsJsonExporter::UnitsJsonExporter(dat::DataHub &datahub) :
mDatahub(datahub)
{
}
UnitsJsonExporter::~UnitsJsonExporter()
{
}
void UnitsJsonExporter::exportUnit(unsigned int id, const std::string &idString)
{
/*Unit unit(mDatahub, id, idString);
json j;
json j_unit(unit);
j["unit"] = j_unit;*/
}
| 562
|
C++
|
.cpp
| 28
| 18
| 80
| 0.743243
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,091
|
scdat2json.cpp
|
Wargus_stargus/tools/scdat2json/scdat2json.cpp
|
/*
* scdat2json.cpp
*
* Author: Andreas Volz
*/
// project
#include "Breeze.h"
#include "Storm.h"
#include "Casc.h"
#include "FileUtil.h"
#include "StringUtil.h"
#include "optparser.h"
#include "dat/DataHub.h"
#include "Storage.h"
#include "SCJsonExporter.h"
#include "UnitsJsonExporter.h"
#include "Logger.h"
#include "pacman.h"
#include "dat/Unit.h"
#include "to_json.h"
// system
#include <iostream>
#include <nlohmann/json.hpp>
#include <fstream>
using namespace std;
using namespace dat;
/**
* The scdat2json tool idea is to export the data in all relevant *.dat and corresponding *.tbl in a raw format to JSON.
* At this point of transformation isn't much format conversation done. Just put the data as in original data structures, but readable.
* Only exception for now is that .tbl files get some basic control sequence parsing.
*/
static Logger logger("startool.scdat2json");
// some global variables
string backend;
string archive;
string destination_directory;
bool pretty = true;
bool CheckCASCDataFolder(const std::string &dir)
{
return FileExists(dir + "/.build.info");
}
/** option parser **/
struct Arg: public option::Arg
{
static void printError(const char *msg1, const option::Option &opt, const char *msg2)
{
fprintf(stderr, "%s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(const option::Option &option, bool msg)
{
if (msg)
printError("Unknown option '", option, "'\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(const option::Option &option, bool msg)
{
if (option.arg != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires an argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus NonEmpty(const option::Option &option, bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a non-empty argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(const option::Option &option, bool msg)
{
char *endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10))
{
};
if (endptr != option.arg && *endptr == 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a numeric argument\n");
return option::ARG_ILLEGAL;
}
};
enum optionIndex
{
UNKNOWN, HELP, BACKEND, PRETTY
};
const option::Descriptor usage[] =
{
{
UNKNOWN, 0, "", "", option::Arg::None, "USAGE: scdat2json [options] archive archive-file destination-directory\n\n"
"Options:"
},
{ HELP, 0, "h", "help", option::Arg::None, " --help, -h \t\tPrint usage and exit" },
{ PRETTY, 0, "p", "pretty", Arg::Required, " --pretty=[yes/no], -p \t\tPretty print the formated JSON file (default: yes)" },
{ BACKEND, 0, "b", "backend", Arg::Required, " --backend, -b \t\tChoose a backend (Storm=St*arcr*ft1/Br**dwar;Casc=Remastered;Breeze=Folder)" },
{
UNKNOWN, 0, "", "", option::Arg::None,
"\narchive \t\tDestination to the archive (mpq, casc or dummy folder) based on backend.\n"
"\ndestination-directory \t\tWhere to save the extracted file with same relative path.\n"
},
{ 0, 0, 0, 0, 0, 0 }
};
int parseOptions(int argc, const char **argv)
{
argc -= (argc > 0);
argv += (argc > 0); // skip program name argv[0] if present
option::Stats stats(usage, argc, argv);
std::unique_ptr<option::Option[]> options(new option::Option[stats.options_max]), buffer(new option::Option[stats.buffer_max]);
option::Parser parse(usage, argc, argv, options.get(), buffer.get());
if (parse.error())
exit(0);
if (options[HELP])
{
option::printUsage(std::cout, usage);
exit(0);
}
if ( options[PRETTY].count() > 0 )
{
if (string(options[PRETTY].arg) == "yes")
{
pretty = true;
}
else if (string(options[PRETTY].arg) == "no")
{
pretty = false;
}
}
if(options[BACKEND].count() > 0)
{
backend = options[BACKEND].arg;
}
else
{
cerr << "Error: 'backend' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
// parse options
for (option::Option *opt = options[UNKNOWN]; opt; opt = opt->next())
std::cout << "Unknown option: " << opt->name << "\n";
for (int i = 0; i < parse.nonOptionsCount(); ++i)
{
switch (i)
{
case 0:
//cerr << "archive #" << i << ": " << parse.nonOption(i) << "\n";
archive = parse.nonOption(i);
break;
case 1:
//cerr << "destination-directory #" << i << ": " << parse.nonOption(i) << "\n";
destination_directory = parse.nonOption(i);
break;
default:
break;
}
}
if (archive.empty())
{
cerr << "Error: 'archive' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
if (destination_directory.empty())
{
cerr << "Error: 'destination_directory' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
return 0;
}
void saveJson(json &j, const std::string &file, bool pretty)
{
std::ofstream filestream(file);
if(pretty)
{
filestream << std::setw(4) << j;
}
else
{
filestream << j;
}
}
int main(int argc, const char **argv)
{
#ifdef HAVE_LOG4CXX
if (FileExists("logging.prop"))
{
log4cxx::PropertyConfigurator::configure("logging.prop");
}
else
{
logger.off();
}
#endif // HAVE_LOG4CXX
parseOptions(argc, argv);
CheckPath(destination_directory);
bool archive_exists = FileExists(archive);
if(!archive_exists)
{
cerr << "archive not existing - exit!" << endl;
exit(1);
}
// read in the json file
std::ifstream json_file(pacman::searchFile("dataset/units.json"));
json units_json; //create unitiialized json object
json_file >> units_json; // initialize json object with what was read from file
shared_ptr<Hurricane> hurricane;
if(to_lower(backend) == "breeze")
{
hurricane = make_shared<Breeze>(archive);
}
else if(to_lower(backend) == "storm")
{
hurricane = make_shared<Storm>(archive);
}
else if(to_lower(backend) == "casc")
{
#ifdef HAVE_CASC
if(CheckCASCDataFolder(archive))
{
hurricane = make_shared<Casc>(archive);
}
else
{
cerr << "Error: 'archive' is not a CASC archive!" << endl;
}
#else
cerr << "Error: No CASC support compiled into sauwetter!" << endl;
exit(1);
#endif
}
dat::DataHub datahub(hurricane);
Storage jsonStorage;
jsonStorage.setDataPath(destination_directory);
//UnitsJsonExporter unitsjsonexporter(datahub);
for(auto &array : units_json)
{
string id_string = array.at("name");
int id = array.at("id");
//unitsjsonexporter.exportUnit(id, id_string);
Unit unit(datahub, id, id_string);
json j_unit(unit);
saveJson(j_unit, jsonStorage(id_string + ".json"), pretty);
}
/*for(unsigned int i = 0; i < datahub.images->grp()->size(); i++)
{
Image image(datahub, i);
json j_image(image);
saveJson(j_image, jsonStorage(image.getIDString() + ".json"), pretty);
}*/
SCJsonExporter scjsonexporter(datahub);
json j_unit_dat = scjsonexporter.export_unit_dat();
saveJson(j_unit_dat, jsonStorage("units_dat.json"), pretty);
json j_orders_dat = scjsonexporter.export_orders_dat();
saveJson(j_orders_dat, jsonStorage("orders_dat.json"), pretty);
json j_weapons_dat = scjsonexporter.export_weapons_dat();
saveJson(j_weapons_dat, jsonStorage("weapons_dat.json"), pretty);
json j_flingy_dat = scjsonexporter.export_flingy_dat();
saveJson(j_flingy_dat, jsonStorage("flingy_dat.json"), pretty);
json j_sprites_dat = scjsonexporter.export_sprites_dat();
saveJson(j_sprites_dat, jsonStorage("sprites_dat.json"), pretty);
json j_images_dat = scjsonexporter.export_images_dat();
saveJson(j_images_dat, jsonStorage("images_dat.json"), pretty);
json j_sfxdata_dat = scjsonexporter.export_sfxdata_dat();
saveJson(j_sfxdata_dat, jsonStorage("sfxdata_dat.json"), pretty);
json j_portdata_dat = scjsonexporter.export_portdata_dat();
saveJson(j_portdata_dat, jsonStorage("portdata_dat.json"), pretty);
json j_upgrades_dat = scjsonexporter.export_upgrades_dat();
saveJson(j_upgrades_dat, jsonStorage("upgrades_dat.json"), pretty);
json j_techdata_dat = scjsonexporter.export_techdata_dat();
saveJson(j_techdata_dat, jsonStorage("techdata_dat.json"), pretty);
json j_mapdata_dat = scjsonexporter.export_mapdata_dat();
saveJson(j_mapdata_dat, jsonStorage("mapdata_dat.json"), pretty);
// export all the .tbl ->
json j_images_tbl = scjsonexporter.export_file_tbl(datahub.images_tbl_vec);
saveJson(j_images_tbl, jsonStorage("images_tbl.json"), pretty);
json j_sfxdata_tbl = scjsonexporter.export_file_tbl(datahub.sfxdata_tbl_vec);
saveJson(j_sfxdata_tbl, jsonStorage("sfxdata_tbl.json"), pretty);
json j_portdata_tbl = scjsonexporter.export_file_tbl(datahub.portdata_tbl_vec);
saveJson(j_portdata_tbl, jsonStorage("portdata_tbl.json"), pretty);
json j_mapdata_tbl = scjsonexporter.export_file_tbl(datahub.mapdata_tbl_vec);
saveJson(j_mapdata_tbl, jsonStorage("mapdata_tbl.json"), pretty);
/// save all the the stat_txt.tbl parts...
json stat_txt_tbl = scjsonexporter.export_file_tbl(datahub.stat_txt_tbl_vec);
saveJson(stat_txt_tbl, jsonStorage("stat_txt_tbl.json"), pretty);
/*json stat_txt_units_tbl = scjsonexporter.export_file_tbl(datahub.stat_txt_units_tbl_vec);
saveJson(stat_txt_units_tbl, jsonStorage("stat_txt_units_tbl.json"), pretty);
json stat_txt_weapons_tbljson = scjsonexporter.export_file_tbl(datahub.stat_txt_weapons_tbl_vec);
saveJson(stat_txt_weapons_tbljson, jsonStorage("stat_txt_weapons_tbl.json"), pretty);
json stat_txt_error_messages_tbl = scjsonexporter.export_file_tbl(datahub.stat_txt_error_messages_tbl_vec);
saveJson(stat_txt_error_messages_tbl, jsonStorage("stat_txt_error_messages_tbl.json"), pretty);
json stat_txt_upgrades_tbl = scjsonexporter.export_file_tbl(datahub.stat_txt_upgrades_tbl_vec);
saveJson(stat_txt_upgrades_tbl, jsonStorage("stat_txt_upgrades_tbl.json"), pretty);
json stat_txt_orders_tbl = scjsonexporter.export_file_tbl(datahub.stat_txt_orders_tbl_vec);
saveJson(stat_txt_orders_tbl, jsonStorage("stat_txt_orders_tbl.json"), pretty);
json stat_txt_techdata_tbl = scjsonexporter.export_file_tbl(datahub.stat_txt_techdata_tbl_vec);
saveJson(stat_txt_techdata_tbl, jsonStorage("stat_txt_techdata_tbl.json"), pretty);*/
cerr << "Application finished!" << endl;
return 0;
}
| 10,675
|
C++
|
.cpp
| 303
| 31.656766
| 148
| 0.686153
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,092
|
to_json.cpp
|
Wargus_stargus/tools/scdat2json/to_json.cpp
|
#include "to_json.h"
#include "StringUtil.h"
#include <iostream>
using namespace std;
using namespace dat;
void to_json(json &j, units_dat_t::hit_points_type_t *t)
{
j = json{ {"hitpoints", t->hitpoints()} };
}
void to_json(json &j, units_dat_t::special_ability_flags_type_t *t)
{
j = json
{
{"building", t->building()},
{"addon", t->addon()},
{"flyer", t->flyer()},
{"resourceminer", t->resourceminer()},
{"subunit", t->subunit()},
{"flyingbuilding", t->flyingbuilding()},
{"hero", t->hero()},
{"regenerate", t->regenerate()},
{"animatedidle", t->animatedidle()},
{"cloakable", t->cloakable()},
{"twounitsinoneegg", t->twounitsinoneegg()},
{"singleentity", t->singleentity()},
{"resourcedepot", t->resourcedepot()},
{"resourcecontainter", t->resourcecontainter()},
{"robotic", t->robotic()},
{"detector", t->detector()},
{"organic", t->organic()},
{"requirescreep", t->requirescreep()},
{"unused", t->unused()},
{"requirespsi", t->requirespsi()},
{"burrowable", t->burrowable()},
{"spellcaster", t->spellcaster()},
{"permanentcloak", t->permanentcloak()},
{"pickupitem", t->pickupitem()},
{"ignoresupplycheck", t->ignoresupplycheck()},
{"usemediumoverlays", t->usemediumoverlays()},
{"uselargeoverlays", t->uselargeoverlays()},
{"battlereactions", t->battlereactions()},
{"fullautoattack", t->fullautoattack()},
{"invincible", t->invincible()},
{"mechanical", t->mechanical()},
{"producesunits", t->producesunits()}
};
}
void to_json(json &j, units_dat_t::staredit_placement_box_type_t *t)
{
j = json{ {"width", t->width()}, {"height", t->height()} };
}
void to_json(json &j, units_dat_t::addon_position_type_t *t)
{
j = json{ {"horizontal", t->horizontal()}, {"vertical", t->vertical()} };
}
void to_json(json &j, units_dat_t::unit_dimension_type_t *t)
{
j = json{ {"left", t->left()}, {"up", t->up()}, {"right", t->right()}, {"down", t->down()} };
}
void to_json(json &j, units_dat_t::staredit_group_flags_type_t *t)
{
j = json
{
{"zerg", t->zerg()},
{"terran", t->terran()},
{"protoss", t->protoss()},
{"men", t->men()},
{"building", t->building()},
{"factory", t->factory()},
{"independent", t->independent()},
{"neutral", t->neutral()}
};
}
void to_json(json &j, units_dat_t::staredit_availability_flags_type_t *t)
{
j = json
{
{"non_neutral", t->non_neutral()},
{"unit_listing", t->unit_listing()},
{"mission_briefing", t->mission_briefing()},
{"player_settings", t->player_settings()},
{"all_races", t->all_races()},
{"set_doodad_state", t->set_doodad_state()},
{"non_location_triggers", t->non_location_triggers()},
{"unit_hero_settings", t->unit_hero_settings()},
{"location_triggers", t->location_triggers()},
{"brood_war_only", t->brood_war_only()}
};
}
NLOHMANN_JSON_SERIALIZE_ENUM(iscript_bin_t::opcode_t,
{
{iscript_bin_t::opcode_t::OPCODE_PLAYFRAM, "playfram"},
{iscript_bin_t::opcode_t::OPCODE_PLAYFRAMTILE, "playframtile"},
{iscript_bin_t::opcode_t::OPCODE_SETHORPOS, "sethorpos"},
{iscript_bin_t::opcode_t::OPCODE_SETVERTPOS, "setvertpos"},
{iscript_bin_t::opcode_t::OPCODE_SETPOS, "setpos"},
{iscript_bin_t::opcode_t::OPCODE_WAIT, "wait"},
{iscript_bin_t::opcode_t::OPCODE_WAITRAND, "waitrand"},
{iscript_bin_t::opcode_t::OPCODE_GOTO, "goto"},
{iscript_bin_t::opcode_t::OPCODE_IMGOL, "imgol"},
{iscript_bin_t::opcode_t::OPCODE_IMGUL, "imgul"},
{iscript_bin_t::opcode_t::OPCODE_IMGOLORIG, "imgolorig"},
{iscript_bin_t::opcode_t::OPCODE_SWITCHUL, "switchul"},
{iscript_bin_t::opcode_t::OPCODE_UNKNOWN_0C, "unknown_0c"},
{iscript_bin_t::opcode_t::OPCODE_IMGOLUSELO, "imgoluselo"},
{iscript_bin_t::opcode_t::OPCODE_IMGULUSELO, "imguluselo"},
{iscript_bin_t::opcode_t::OPCODE_SPROL, "sprol"},
{iscript_bin_t::opcode_t::OPCODE_HIGHSPROL, "highsprol"},
{iscript_bin_t::opcode_t::OPCODE_LOWSPRUL, "lowsprul"},
{iscript_bin_t::opcode_t::OPCODE_UFLUNSTABLE, "uflunstable"},
{iscript_bin_t::opcode_t::OPCODE_SPRULUSELO, "spruluselo"},
{iscript_bin_t::opcode_t::OPCODE_SPRUL, "sprul"},
{iscript_bin_t::opcode_t::OPCODE_SPROLUSELO, "sproluselo"},
{iscript_bin_t::opcode_t::OPCODE_END, "end"},
{iscript_bin_t::opcode_t::OPCODE_SETFLIPSTATE, "setflipstate"},
{iscript_bin_t::opcode_t::OPCODE_PLAYSND, "playsnd"},
{iscript_bin_t::opcode_t::OPCODE_PLAYSNDRAND, "playsndrand"},
{iscript_bin_t::opcode_t::OPCODE_PLAYSNDBTWN, "playsndbtwn"},
{iscript_bin_t::opcode_t::OPCODE_DOMISSILEDMG, "domissiledmg"},
{iscript_bin_t::opcode_t::OPCODE_ATTACKMELEE, "attackmelee"},
{iscript_bin_t::opcode_t::OPCODE_FOLLOWMAINGRAPHIC, "followmaingraphic"},
{iscript_bin_t::opcode_t::OPCODE_RANDCONDJMP, "randcondjmp"},
{iscript_bin_t::opcode_t::OPCODE_TURNCCWISE, "turnccwise"},
{iscript_bin_t::opcode_t::OPCODE_TURNCWISE, "turncwise"},
{iscript_bin_t::opcode_t::OPCODE_TURN1CWISE, "turn1cwise"},
{iscript_bin_t::opcode_t::OPCODE_TURNRAND, "turnrand"},
{iscript_bin_t::opcode_t::OPCODE_SETSPAWNFRAME, "setspawnframe"},
{iscript_bin_t::opcode_t::OPCODE_SIGORDER, "sigorder"},
{iscript_bin_t::opcode_t::OPCODE_ATTACKWITH, "attackwith"},
{iscript_bin_t::opcode_t::OPCODE_ATTACK, "attack"},
{iscript_bin_t::opcode_t::OPCODE_CASTSPELL, "castspell"},
{iscript_bin_t::opcode_t::OPCODE_USEWEAPON, "useweapon"},
{iscript_bin_t::opcode_t::OPCODE_MOVE, "move"},
{iscript_bin_t::opcode_t::OPCODE_GOTOREPEATATTK, "gotorepeatattk"},
{iscript_bin_t::opcode_t::OPCODE_ENGFRAME, "engframe"},
{iscript_bin_t::opcode_t::OPCODE_ENGSET, "engset"},
{iscript_bin_t::opcode_t::OPCODE_UNKNOWN_2D, "unknown_2d"},
{iscript_bin_t::opcode_t::OPCODE_NOBRKCODESTART, "nobrkcodestart"},
{iscript_bin_t::opcode_t::OPCODE_NOBRKCODEEND, "nobrkcodeend"},
{iscript_bin_t::opcode_t::OPCODE_IGNOREREST, "ignorerest"},
{iscript_bin_t::opcode_t::OPCODE_ATTKSHIFTPROJ, "attkshiftproj"},
{iscript_bin_t::opcode_t::OPCODE_TMPRMGRAPHICSTART, "tmprmgraphicstart"},
{iscript_bin_t::opcode_t::OPCODE_TMPRMGRAPHICEND, "tmprmgraphicend"},
{iscript_bin_t::opcode_t::OPCODE_SETFLDIRECT, "setfldirect"},
{iscript_bin_t::opcode_t::OPCODE_CALL, "call"},
{iscript_bin_t::opcode_t::OPCODE_RETURN, "return"},
{iscript_bin_t::opcode_t::OPCODE_SETFLSPEED, "setflspeed"},
{iscript_bin_t::opcode_t::OPCODE_CREATEGASOVERLAYS, "creategasoverlays"},
{iscript_bin_t::opcode_t::OPCODE_PWRUPCONDJMP, "pwrupcondjmp"},
{iscript_bin_t::opcode_t::OPCODE_TRGTRANGECONDJMP, "trgtrangecondjmp"},
{iscript_bin_t::opcode_t::OPCODE_TRGTARCCONDJMP, "trgtarccondjmp"},
{iscript_bin_t::opcode_t::OPCODE_CURDIRECTCONDJMP, "curdirectcondjmp"},
{iscript_bin_t::opcode_t::OPCODE_IMGULNEXTID, "imgulnextid"},
{iscript_bin_t::opcode_t::OPCODE_UNKNOWN_3E, "unknown_3e"},
{iscript_bin_t::opcode_t::OPCODE_LIFTOFFCONDJMP, "liftoffcondjmp"},
{iscript_bin_t::opcode_t::OPCODE_WARPOVERLAY, "warpoverlay"},
{iscript_bin_t::opcode_t::OPCODE_ORDERDONE, "orderdone"},
{iscript_bin_t::opcode_t::OPCODE_GRDSPROL, "grdsprol"},
{iscript_bin_t::opcode_t::OPCODE_UNKNOWN_43, "unknown_43"},
{iscript_bin_t::opcode_t::OPCODE_DOGRDDAMAGE, "dogrddamage"},
})
void to_json(json &j, iscript_bin_t::u2_type_t *u2)
{
j = json(to_string(u2->value()));
}
void to_json(json &j, iscript_bin_t::u1_type_t *u1)
{
j = json(to_string(u1->value()));
}
void to_json(json &j, iscript_bin_t::pos_type_t *pos)
{
j["x"] = json(to_string(pos->x()));
j["y"] = json(to_string(pos->y()));
}
void to_json(json &j, iscript_bin_t::playsndbtwn_type_t *snd)
{
j["firstsound"] = json(to_string(snd->firstsound()));
j["lastsound"] = json(to_string(snd->lastsound()));
}
void to_json(json &j, iscript_bin_t::trgcondjmp_type_t *trgcondjmp)
{
j["angle1"] = json(to_string(trgcondjmp->angle1()));
j["angle2"] = json(to_string(trgcondjmp->angle2()));
j["labelname"] = json(to_string(trgcondjmp->labelname()));
}
void to_json(json &j, iscript_bin_t::imgl_type_t *imgl)
{
j["image"] = json(to_string(imgl->image()));
j["pos"] = json(imgl->pos());
}
void to_json(json &j, iscript_bin_t::sprl_type_t *sprl)
{
j["sprite"] = json(to_string(sprl->sprite()));
j["pos"] = json(sprl->pos());
}
void to_json(json &j, iscript_bin_t::trgtrangecondjmp_type_t *ttcj)
{
j["distance"] = json(to_string(ttcj->distance()));
j["labelname"] = json(ttcj->labelname());
}
void to_json(json &j, iscript_bin_t::randcondjmp_type_t *rcj)
{
j["randchance"] = json(to_string(rcj->randchance()));
j["labelname"] = json(rcj->labelname());
}
void to_json(json &j, iscript_bin_t::playsounds_type_t *ps)
{
j = json::array();
for(auto sound : *(ps->sound()))
{
j.push_back(to_string(sound));
}
}
void to_json(json &j, iscript_bin_t::sprov_type_t *sprov)
{
j["sprite"] = json(to_string(sprov->sprite()));
j["overlay"] = json(to_string(sprov->overlay()));
}
void to_json(json &j, iscript_bin_t::waitrand_type_t *wr)
{
j["ticks1"] = json(to_string(wr->ticks1()));
j["ticks2"] = json(to_string(wr->ticks2()));
}
void to_json(json &j, iscript_bin_t::opcode_type_t *opcode)
{
iscript_bin_t::opcode_t opcode_code_enum = opcode->code();
string opcode_code_name = json(opcode_code_enum);
switch (opcode_code_enum)
{
case iscript_bin_t::OPCODE_TURN1CWISE:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_IMGOLORIG:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_3E:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_SIGORDER:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_ENGFRAME:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TURNCCWISE:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_2D:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_END:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_PLAYFRAM:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TMPRMGRAPHICSTART:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_IMGULNEXTID:
{
iscript_bin_t::pos_type_t *casted_args = static_cast<iscript_bin_t::pos_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_PLAYSNDBTWN:
{
iscript_bin_t::playsndbtwn_type_t *casted_args = static_cast<iscript_bin_t::playsndbtwn_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_0C:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_ENGSET:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SWITCHUL:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TRGTARCCONDJMP:
{
iscript_bin_t::trgcondjmp_type_t *casted_args = static_cast<iscript_bin_t::trgcondjmp_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SETFLIPSTATE:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SETPOS:
{
iscript_bin_t::pos_type_t *casted_args = static_cast<iscript_bin_t::pos_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_IMGOLUSELO:
{
iscript_bin_t::imgl_type_t *casted_args = static_cast<iscript_bin_t::imgl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_LOWSPRUL:
{
iscript_bin_t::sprl_type_t *casted_args = static_cast<iscript_bin_t::sprl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TURNRAND:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_DOMISSILEDMG:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_HIGHSPROL:
{
iscript_bin_t::sprl_type_t *casted_args = static_cast<iscript_bin_t::sprl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SETFLSPEED:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_USEWEAPON:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_WARPOVERLAY:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_GOTOREPEATATTK:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_UFLUNSTABLE:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_ORDERDONE:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TRGTRANGECONDJMP:
{
iscript_bin_t::trgtrangecondjmp_type_t *casted_args = static_cast<iscript_bin_t::trgtrangecondjmp_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_RETURN:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_CASTSPELL:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_FOLLOWMAINGRAPHIC:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_RANDCONDJMP:
{
iscript_bin_t::randcondjmp_type_t *casted_args = static_cast<iscript_bin_t::randcondjmp_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_NOBRKCODEEND:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_CALL:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_NOBRKCODESTART:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_WAIT:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SPROL:
{
iscript_bin_t::sprl_type_t *casted_args = static_cast<iscript_bin_t::sprl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TMPRMGRAPHICEND:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_CREATEGASOVERLAYS:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SETFLDIRECT:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_PWRUPCONDJMP:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SETHORPOS:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SPRULUSELO:
{
iscript_bin_t::sprl_type_t *casted_args = static_cast<iscript_bin_t::sprl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SPRUL:
{
iscript_bin_t::sprl_type_t *casted_args = static_cast<iscript_bin_t::sprl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_GRDSPROL:
{
iscript_bin_t::sprl_type_t *casted_args = static_cast<iscript_bin_t::sprl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_MOVE:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_GOTO:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_IMGUL:
{
iscript_bin_t::imgl_type_t *casted_args = static_cast<iscript_bin_t::imgl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_PLAYFRAMTILE:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_ATTKSHIFTPROJ:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_LIFTOFFCONDJMP:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_IMGOL:
{
iscript_bin_t::imgl_type_t *casted_args = static_cast<iscript_bin_t::imgl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_IMGULUSELO:
{
iscript_bin_t::imgl_type_t *casted_args = static_cast<iscript_bin_t::imgl_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_ATTACK:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_ATTACKMELEE:
{
iscript_bin_t::playsounds_type_t *casted_args = static_cast<iscript_bin_t::playsounds_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SPROLUSELO:
{
iscript_bin_t::sprov_type_t *casted_args = static_cast<iscript_bin_t::sprov_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_PLAYSNDRAND:
{
iscript_bin_t::playsounds_type_t *casted_args = static_cast<iscript_bin_t::playsounds_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_IGNOREREST:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_PLAYSND:
{
iscript_bin_t::u2_type_t *casted_args = static_cast<iscript_bin_t::u2_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_43:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_SETVERTPOS:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_DOGRDDAMAGE:
{
j[opcode_code_name] = nullptr;
break;
}
case iscript_bin_t::OPCODE_WAITRAND:
{
iscript_bin_t::waitrand_type_t *casted_args = static_cast<iscript_bin_t::waitrand_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_TURNCWISE:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_CURDIRECTCONDJMP:
{
iscript_bin_t::trgcondjmp_type_t *casted_args = static_cast<iscript_bin_t::trgcondjmp_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_SETSPAWNFRAME:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
case iscript_bin_t::OPCODE_ATTACKWITH:
{
iscript_bin_t::u1_type_t *casted_args = static_cast<iscript_bin_t::u1_type_t *>(opcode->args());
j[opcode_code_name] = json(casted_args);
break;
}
default:
{
j[opcode_code_name] = nullptr;
break;
}
}
}
void to_json(json &j, std::vector<iscript_bin_t::opcode_type_t *> opcode_vec)
{
j = json::array();
for (auto opcode : opcode_vec)
{
j.push_back(opcode);
}
}
namespace dat
{
void to_json(json &j, TblEntry t)
{
j = json
{
{"name1", t.name1()},
{"name2", t.name2()},
{"name3", t.name3()},
{"shortcut_pos", t.shortcut_pos()},
{"shortcut", t.shortcut()}
};
}
void to_json(json &j, Upgrade u)
{
j["id"] = json(u.id());
j["mineral_cost_base"] = json(u.mineral_cost_base());
j["mineral_cost_factor"] = json(u.mineral_cost_factor());
j["vespene_cost_base"] = json(u.vespene_cost_base());
j["vespene_cost_factor"] = json(u.vespene_cost_factor());
j["research_time_base"] = json(u.research_time_base());
j["research_time_factor"] = json(u.research_time_factor());
j["unknown6"] = json(u.unknown6());
j["icon"] = json(u.icon());
j["label"] = json(u.label());
j["label_tbl"] = json(u.label_tbl());
j["race"] = json(u.race());
j["max_repeats"] = json(u.max_repeats());
if (u.has_broodwar_flag())
{
j["broodwar_flags"] = json(u.broodwar_flags());
}
}
void to_json(json &j, Order o)
{
j["id"] = json(o.id());
j["label"] = json(o.label());
j["label_tbl"] = json(o.label_tbl());
j["use_weapon_targeting"] = json(o.use_weapon_targeting());
j["unknown2"] = json(o.unknown2());
j["unknown3"] = json(o.unknown3());
j["unknown4"] = json(o.unknown4());
j["unknown5"] = json(o.unknown5());
j["interruptible"] = json(o.interruptible());
j["unknown7"] = json(o.unknown7());
j["queueable"] = json(o.queueable());
j["unknown9"] = json(o.unknown9());
j["unknown10"] = json(o.unknown10());
j["unknown11"] = json(o.unknown11());
j["unknown12"] = json(o.unknown12());
j["targeting"] = json(o.targeting());
try
{
j["targeting_obj"] = json(o.targeting_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["energy"] = json(o.energy());
try
{
j["energy_obj"] = json(o.energy_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["animation"] = json(o.animation());
j["highlight"] = json(o.highlight());
j["unknown17"] = json(o.unknown17());
j["obscured_order"] = json(o.obscured_order());
//j["obscured_order_obj"] = json(o.obscured_order_obj());
}
void to_json(json &j, Techdata t)
{
j["id"] = json(t.id());
j["mineral_cost"] = json(t.mineral_cost());
j["vespene_cost"] = json(t.vespene_cost());
j["research_time"] = json(t.research_time());
j["energy_required"] = json(t.energy_required());
j["unknown4"] = json(t.unknown4());
j["icon"] = json(t.icon());
j["label"] = json(t.label());
j["race"] = json(t.race());
j["unused"] = json(t.unused());
if (t.has_broodwar_flag())
{
j["broodwar_flag"] = json(t.broodwar_flag());
}
}
void to_json(json &j, Weapon w)
{
j["id"] = json(w.id());
j["label"] = json(w.label());
j["label_tbl"] = json(w.label_tbl());
j["graphics"] = json(w.graphics());
j["graphics_obj"] = json(w.graphics_obj());
j["explosion"] = json(w.explosion());
j["target_flags"] = json(w.target_flags());
j["minimum_range"] = json(w.minimum_range());
j["maximum_range"] = json(w.maximum_range());
j["damage_upgrade"] = json(w.damage_upgrade());
j["damage_upgrade_obj"] = json(w.damage_upgrade_obj());
j["weapon_type"] = json(w.weapon_type());
j["weapon_behaviour"] = json(w.weapon_behaviour());
j["remove_after"] = json(w.remove_after());
j["explosive_type"] = json(w.explosive_type());
j["inner_splash_range"] = json(w.inner_splash_range());
j["medium_splash_range"] = json(w.medium_splash_range());
j["outer_splash_range"] = json(w.outer_splash_range());
j["damage_amount"] = json(w.damage_amount());
j["damage_bonus"] = json(w.damage_bonus());
j["weapon_cooldown"] = json(w.weapon_cooldown());
j["damage_factor"] = json(w.damage_factor());
j["attack_angle"] = json(w.attack_angle());
j["launch_spin"] = json(w.launch_spin());
j["x_offset"] = json(w.x_offset());
j["y_offset"] = json(w.y_offset());
j["error_message"] = json(w.error_message());
j["error_message_tbl"] = json(w.error_message_tbl());
j["icon"] = json(w.icon());
}
void to_json(json &j, Sfx s)
{
j = json
{
{"id", s.id()},
{"sound_file", s.sound_file()},
{"sound_file_tbl", s.sound_file_tbl()},
{"unknown1", s.unknown1()},
{"unknown2", s.unknown2()},
{"unknown3", s.unknown3()},
{"unknown4", s.unknown4()}
};
}
void to_json(json &j, Portrait p)
{
j = json
{
{"id", p.id()},
{"video_idle", p.video_idle()},
{"video_idle_tbl", p.video_idle_tbl()},
{"video_talking", p.video_talking()},
{"video_talking_tbl", p.video_talking_tbl()},
{"change_idle", p.change_idle()},
{"change_talking", p.change_talking()},
{"unknown1_idle", p.unknown1_idle()},
{"unknown1_talking", p.unknown1_talking()}
};
}
NLOHMANN_JSON_SERIALIZE_ENUM(IScript::AnimationType,
{
{IScript::AnimationType::Init, "Init"},
{IScript::AnimationType::Death, "Death"},
{IScript::AnimationType::GndAttkInit, "GndAttkInit"},
{IScript::AnimationType::AirAttkInit, "AirAttkInit"},
{IScript::AnimationType::Unused1, "Unused1"},
{IScript::AnimationType::GndAttkRpt, "GndAttkRpt"},
{IScript::AnimationType::AirAttkRpt, "AirAttkRpt"},
{IScript::AnimationType::CastSpell, "CastSpell"},
{IScript::AnimationType::GndAttkToIdle, "GndAttkToIdle"},
{IScript::AnimationType::AirAttkToIdle, "AirAttkToIdle"},
{IScript::AnimationType::Unused2, "Unused2"},
{IScript::AnimationType::Walking, "Walking"},
{IScript::AnimationType::WalkingToIdle, "WalkingToIdle"},
{IScript::AnimationType::SpecialState1, "SpecialState1"},
{IScript::AnimationType::SpecialState2, "SpecialState2"},
{IScript::AnimationType::AlmostBuilt, "AlmostBuilt"},
{IScript::AnimationType::Built, "Built"},
{IScript::AnimationType::Landing, "Landing"},
{IScript::AnimationType::LiftOff, "LiftOff"},
{IScript::AnimationType::IsWorking, "IsWorking"},
{IScript::AnimationType::WorkingToIdle, "WorkingToIdle"},
{IScript::AnimationType::WarpIn, "WarpIn"},
{IScript::AnimationType::Unused3, "Unused3"},
{IScript::AnimationType::StarEditInit, "StarEditInit"},
{IScript::AnimationType::Disable, "Disable"},
{IScript::AnimationType::Burrow, "Burrow"},
{IScript::AnimationType::UnBurrow, "UnBurrow"},
{IScript::AnimationType::Enable, "Enable"},
})
void to_json(json &j, IScript is)
{
int animation_count = is.getAnimationCount();
for (int i = 0; i < animation_count; i++)
{
IScript::AnimationType anim_t = static_cast<IScript::AnimationType>(i);
string anim_name = json(anim_t);
std::vector<iscript_bin_t::opcode_type_t *> opcode_vec = is.getAnimationScript(i);
j[anim_name] = json(opcode_vec);
}
}
void to_json(json &j, Image i)
{
j["id"] = json(i.id());
j["grp"] = json(i.grp());
j["grp_tbl"] = json(i.grp_tbl());
j["gfx_turns"] = json(i.gfx_turns());
j["clickable"] = json(i.clickable());
j["use_full_iscript"] = json(i.use_full_iscript());
j["draw_if_cloaked"] = json(i.draw_if_cloaked());
j["draw_function"] = json(i.draw_function());
j["remapping"] = json(i.remapping());
j["iscript"] = json(i.iscript());
j["iscript_obj"] = json(i.iscript_obj());
j["shield_overlay"] = json(i.shield_overlay());
try
{
j["shield_overlay_tbl"] = json(i.shield_overlay_tbl());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["attack_overlay"] = json(i.attack_overlay());
try
{
j["attack_overlay_tbl"] = json(i.attack_overlay_tbl());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["damage_overlay"] = json(i.damage_overlay());
try
{
j["damage_overlay_tbl"] = json(i.damage_overlay_tbl());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["special_overlay"] = json(i.special_overlay());
try
{
j["special_overlay_tbl"] = json(i.special_overlay_tbl());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["landing_dust_overlay"] = json(i.landing_dust_overlay());
try
{
j["landing_dust_overlay_tbl"] = json(i.landing_dust_overlay_tbl());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
}
void to_json(json &j, Sprite s)
{
j["id"] = json(s.id());
j["image"] = json(s.image());
j["image_obj"] = json(s.image_obj());
try
{
j["health_bar"] = json(s.health_bar());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["unknown2"] = json(s.unknown2());
j["is_visible"] = json(s.is_visible());
try
{
j["select_circle_image_size"] = json(s.select_circle_image_size());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["select_circle_vertical_pos"] = json(s.select_circle_vertical_pos());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
}
void to_json(json &j, Flingy f)
{
j = json
{
{"id", f.id()},
{"sprite", f.sprite()},
{"sprite_obj", f.sprite_obj()},
{"speed", f.speed()},
{"acceleration", f.acceleration()},
{"halt_distance", f.halt_distance()},
{"turn_radius", f.turn_radius()},
{"unused", f.unused()},
{"movement_control", f.movement_control()}
};
}
void to_json(json &j, Unit u)
{
j["id"] = json(u.id());
j["id_string"] = json(u.getIDString());
j["name_tbl"] = json(u.name_tbl());
j["flingy"] = json(u.flingy());
j["flingy_obj"] = json(u.flingy_obj());
j["subunit1"] = json(u.subunit1());
try
{
j["subunit1_obj"] = json(u.subunit1_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["subunit2"] = json(u.subunit2());
try
{
j["subunit2_obj"] = json(u.subunit2_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["infestation"] = json(u.infestation());
j["infestation_obj"] = json(u.infestation_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["construction_animation"] = json(u.construction_animation());
j["construction_animation_obj"] = json(u.construction_animation_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["unit_direction"] = json(u.unit_direction());
j["shield_enable"] = json(u.shield_enable());
j["shield_amount"] = json(u.shield_amount());
j["hitpoints"] = json(u.hitpoints());
j["elevation_level"] = json(u.elevation_level());
j["unknown"] = json(u.unknown());
j["rank"] = json(u.rank());
j["ai_computer_idle"] = json(u.ai_computer_idle());
j["ai_computer_idle_obj"] = json(u.ai_computer_idle_obj());
j["ai_human_idle"] = json(u.ai_human_idle());
j["ai_human_idle_obj"] = json(u.ai_human_idle_obj());
j["ai_return_to_idle"] = json(u.ai_return_to_idle());
j["ai_return_to_idle_obj"] = json(u.ai_return_to_idle_obj());
j["ai_attack_unit"] = json(u.ai_attack_unit());
j["ai_attack_unit_obj"] = json(u.ai_attack_unit_obj());
j["ai_attack_move"] = json(u.ai_attack_move());
j["ai_attack_move_obj"] = json(u.ai_attack_move_obj());
try
{
j["ground_weapon"] = json(u.ground_weapon());
j["ground_weapon_obj"] = json(u.ground_weapon_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
if (u.is_format_bw())
{
j["max_ground_hits"] = json(u.max_ground_hits());
}
try
{
j["air_weapon"] = json(u.air_weapon());
j["air_weapon_obj"] = json(u.air_weapon_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
if (u.is_format_bw())
{
j["max_air_hits"] = json(u.max_air_hits());
}
j["ai_internal"] = json(u.ai_internal());
j["special_ability_flags"] = json(u.special_ability_flags());
j["target_acquisition_range"] = json(u.target_acquisition_range());
j["sight_range"] = json(u.sight_range());
j["armor_upgrade"] = json(u.armor_upgrade());
j["unit_size"] = json(u.unit_size());
j["armor"] = json(u.armor());
j["right_click_action"] = json(u.right_click_action());
try
{
j["ready_sound"] = json(u.ready_sound());
j["ready_sound_obj"] = json(u.ready_sound_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["what_sound_start"] = json(u.what_sound_start());
j["what_sound_end"] = json(u.what_sound_end());
j["what_sound_obj"] = json(u.what_sound_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["piss_sound_start"] = json(u.piss_sound_start());
j["piss_sound_end"] = json(u.piss_sound_end());
j["piss_sound_obj"] = json(u.piss_sound_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["what_sound_start"] = json(u.what_sound_start());
j["what_sound_end"] = json(u.what_sound_end());
j["what_sound_obj"] = json(u.what_sound_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
try
{
j["yes_sound_start"] = json(u.yes_sound_start());
j["yes_sound_end"] = json(u.yes_sound_end());
j["yes_sound_obj"] = json(u.yes_sound_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["staredit_placement_box"] = json(u.staredit_placement_box());
try
{
j["addon_position"] = json(u.addon_position());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["unit_dimension"] = json(u.unit_dimension());
j["portrait"] = json(u.portrait());
try
{
j["portrait_obj"] = json(u.portrait_obj());
}
catch (PropertyNotAvailableException &ex)
{ /*it's fine, do nothing */ }
j["mineral_cost"] = json(u.mineral_cost());
j["vespene_cost"] = json(u.vespene_cost());
j["build_time"] = json(u.build_time());
j["requirements"] = json(u.requirements());
j["staredit_group_flags"] = json(u.staredit_group_flags());
j["supply_required"] = json(u.supply_required());
j["space_provided"] = json(u.space_provided());
j["build_score"] = json(u.build_score());
j["destroy_score"] = json(u.destroy_score());
j["unit_map_string"] = json(u.unit_map_string());
if (u.is_format_bw())
{
j["broodwar_flag"] = json(u.broodwar_flag());
}
j["is_format_bw"] = json(u.is_format_bw());
}
} /* namespace dat */
| 36,201
|
C++
|
.cpp
| 1,072
| 30.30597
| 128
| 0.648679
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,093
|
grptool.cpp
|
Wargus_stargus/tools/grptool/grptool.cpp
|
/*
* grptool.cpp
*
* Author: Andreas Volz
*/
// project
#include "optparser.h"
#include "libgrp/libgrp.hpp"
#include "Logger.h"
#include "FileUtil.h"
#include "Breeze.h"
#include "NoValidPaletteException.h"
#include "Palette2D.h"
// system
#include <iostream>
#include <memory>
using namespace std;
/**
* Description
*/
static Logger logger("grptool");
// some global variables
string palette_file;
string grp_file;
bool duplicates = true;
bool single_stiched = true;
int image_per_row = 10;
bool rgba = false;
/** option parser **/
struct Arg: public option::Arg
{
static void printError(const char *msg1, const option::Option &opt, const char *msg2)
{
fprintf(stderr, "%s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(const option::Option &option, bool msg)
{
if (msg)
printError("Unknown option '", option, "'\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(const option::Option &option, bool msg)
{
if (option.arg != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires an argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus NonEmpty(const option::Option &option, bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a non-empty argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(const option::Option &option, bool msg)
{
char *endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10))
{
};
if (endptr != option.arg && *endptr == 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a numeric argument\n");
return option::ARG_ILLEGAL;
}
};
enum optionIndex
{
UNKNOWN, HELP, PALETTE, DUPLICATES, IMAGE_ROW, SINGLE_FRAMES, RGBA
};
const option::Descriptor usage[] =
{
{
UNKNOWN, 0, "", "", option::Arg::None, "USAGE: grptool [options] grp-file\n\n"
"Options:"
},
{ HELP, 0, "h", "help", option::Arg::None, " --help, -h \t\tPrint usage and exit" },
{ RGBA, 0, "r", "rgba", option::Arg::None, " --rgba, -r \t\tForce RGBA PNG export for 8-bit palettes" },
{ DUPLICATES, 0, "d", "duplicates", Arg::Required, " --duplicates yes|no, -d yes|no \t\tgenerate duplicate frames (default: yes)" },
{ PALETTE, 0, "p", "palette", Arg::Required, " --palette, -p \t\tSpecify the path to a palette file" },
{ IMAGE_ROW, 0, "i", "image-row", Arg::Numeric, " --image-row, -i \t\tIf stitching is enabled, how many images should be saved per row (default: 10)" },
{ SINGLE_FRAMES, 0, "s", "single-frames", Arg::None, " --single-frames, -s \t\tExport each frame into one image (default: all stitched together)" },
{
UNKNOWN, 0, "", "", option::Arg::None,
"\ngrp-file \t\tThe GRP file which should be converted.\n"
},
{ 0, 0, 0, 0, 0, 0 }
};
int parseOptions(int argc, const char **argv)
{
argc -= (argc > 0);
argv += (argc > 0); // skip program name argv[0] if present
option::Stats stats(usage, argc, argv);
std::unique_ptr<option::Option[]> options(new option::Option[stats.options_max]), buffer(new option::Option[stats.buffer_max]);
option::Parser parse(usage, argc, argv, options.get(), buffer.get());
if (parse.error())
exit(0);
if (options[HELP])
{
option::printUsage(std::cout, usage);
exit(0);
}
if ( options[DUPLICATES].count() > 0 )
{
if(string(options[DUPLICATES].arg) == "no")
{
duplicates = false;
}
else
{
duplicates = true;
}
}
if(options[IMAGE_ROW].count() > 0)
{
image_per_row = stoi(options[IMAGE_ROW].arg);
}
if(options[SINGLE_FRAMES].count() > 0)
{
single_stiched = false;
}
if(options[PALETTE].count() > 0)
{
palette_file = options[PALETTE].arg;
}
else
{
cerr << "Error: 'palette' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
if(options[RGBA].count() > 0 )
{
rgba = true;
}
// parse options
for (option::Option *opt = options[UNKNOWN]; opt; opt = opt->next())
std::cout << "Unknown option: " << opt->name << "\n";
for (int i = 0; i < parse.nonOptionsCount(); ++i)
{
switch (i)
{
case 0:
grp_file = parse.nonOption(i);
break;
default:
break;
}
}
if (grp_file.empty())
{
cerr << "Error: 'archive' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
return 0;
}
int main(int argc, const char **argv)
{
#ifdef HAVE_LOG4CXX
if (FileExists("logging.prop"))
{
log4cxx::PropertyConfigurator::configure("logging.prop");
}
else
{
logger.off();
}
#endif // HAVE_LOG4CXX
parseOptions(argc, argv);
std::shared_ptr<AbstractPalette> myGRPPallete;
try
{
shared_ptr<DataChunk> dc = make_shared<DataChunk>();
dc->read(palette_file);
myGRPPallete = AbstractPalette::create(dc);
}
catch(NoValidPaletteException &palEx)
{
cerr << palEx.what() << endl;
}
bool grp_file_exist = FileExists(grp_file);
if(!grp_file_exist)
{
cerr << "GRP file not existing - Exit!" << endl;
exit(1);
}
if(myGRPPallete)
{
//myGRPPallete->write("test.pal");
GRPImage myGRPImage(grp_file, !duplicates);
myGRPImage.SetColorPalette(myGRPPallete);
//image_per_row=17 => starcraft
if(single_stiched)
{
myGRPImage.SaveStitchedPNG("output_frame.png", 0, myGRPImage.getNumberOfFrames(), image_per_row, rgba);
}
else
{
myGRPImage.SaveSinglePNG("output_frame%d.png", 0, myGRPImage.getNumberOfFrames(), rgba);
}
//myGRPImage.SaveConvertedImage("output_frame_magic.png", 0, myGRPImage.getNumberOfFrames(), single_stiched, image_per_row);
//myGRPImage.LoadImage(grp_file, remove_duplicates);
//myGRPImage.SaveConvertedImage("output_big_file.png", 0, myGRPImage.getNumberOfFrames(), false, 17);
}
else
{
cerr << "Palette not successful loaded - Exit!" << endl;
exit(1);
}
cout << "Application finished!" << endl;
return 0;
}
| 6,204
|
C++
|
.cpp
| 219
| 24.634703
| 156
| 0.64311
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,094
|
Casc.cpp
|
Wargus_stargus/src/Casc.cpp
|
/*
* Casc.cpp
*
* Author: Andreas Volz
*/
#ifdef HAVE_CASC
// Local
#include "Casc.h"
#include "FileUtil.h"
// System
#include "CascLib.h"
#include <cstdio>
#include <iostream>
using namespace std;
Casc::Casc() :
mStorage(nullptr)
{
}
Casc::Casc(const std::string &archiveName) :
mStorage(nullptr)
{
openArchive(archiveName);
}
Casc::~Casc()
{
closeArchive();
}
bool Casc::openArchive(const std::string &archiveName)
{
bool result = true;
// close it in case it's still open
closeArchive();
if (!CascOpenStorage(archiveName.c_str(), 0, &mStorage))
{
result = false;
}
else
{
mArchiveName = archiveName;
}
return result;
}
void Casc::closeArchive()
{
if (mStorage != nullptr)
{
CascCloseStorage(mStorage);
mArchiveName.clear();
}
}
// Not in class member to be not expose Casc to public header
PCASC_FILE_SPAN_INFO GetFileSpanInfo(HANDLE hFile)
{
PCASC_FILE_SPAN_INFO pSpans = NULL;
size_t cbLength = 0;
// Retrieve the full file info
CascGetFileInfo(hFile, CascFileSpanInfo, pSpans, cbLength, &cbLength);
if (cbLength != 0)
{
if ((pSpans = (PCASC_FILE_SPAN_INFO)(new BYTE[cbLength])) != NULL)
{
if (CascGetFileInfo(hFile, CascFileSpanInfo, pSpans, cbLength, NULL))
return pSpans;
// in case of error...
//free(pSpans); // TODO: this results in warning - not sure why
pSpans = NULL;
}
}
return pSpans;
}
bool Casc::extractMemory(const std::string &archivedFile,
unsigned char **szEntryBufferPrt, size_t *bufferLen)
{
HANDLE hFile = nullptr;
bool result = true;
unsigned char *szEntryBuffer = nullptr;
// Open a file in the storage
if (CascOpenFile(mStorage, archivedFile.c_str(), 0, 0, &hFile))
{
// Read the data from the file
char szBuffer[0x10000];
DWORD dwBytes = 1;
// quick check if file has valid info
// TODO: later more details to read out!
PCASC_FILE_SPAN_INFO cascFileInfo = GetFileSpanInfo(hFile);
if (cascFileInfo)
{
int i = 0;
size_t len = 0;
szEntryBuffer = (unsigned char *) malloc(sizeof(szBuffer)); // TODO: this might me useless and then free() could be avoid below
while (dwBytes > 0)
{
CascReadFile(hFile, szBuffer, sizeof(szBuffer), &dwBytes);
if (dwBytes > 0)
{
len = len + dwBytes;
szEntryBuffer = (unsigned char *) realloc(szEntryBuffer, len);
memcpy(szEntryBuffer + (i * sizeof(szBuffer)), szBuffer, dwBytes);
}
i++;
}
if (bufferLen != NULL)
{
*bufferLen = len;
}
if (hFile != nullptr)
{
CascCloseFile(hFile);
}
}
else
{
cout << "*NOT* Extracting file (invalid info!): " << archivedFile << endl;
}
}
else
{
cout << "Error: CascOpenFile" << endl;
result = false;
// in case of problem free what ever has been allocated
free(szEntryBuffer);
szEntryBuffer = nullptr;
}
*szEntryBufferPrt = szEntryBuffer;
return result;
}
// TODO 'compress' doesn't work!!
bool Casc::extractFile(const std::string &archivedFile,
const std::string &extractedName, bool compress)
{
HANDLE hFile = NULL;
FILE *fileHandle = NULL;
bool result = true;
// Open a file in the storage
if (CascOpenFile(mStorage, archivedFile.c_str(), 0, 0, &hFile))
{
// Read the data from the file
char szBuffer[0x10000];
DWORD dwBytes = 1;
// quick check if file has valid info
// TODO: later more details to read out!
PCASC_FILE_SPAN_INFO cascFileInfo = GetFileSpanInfo(hFile);
if (cascFileInfo)
{
CheckPath(extractedName.c_str());
fileHandle = fopen(extractedName.c_str(), "wb");
while (dwBytes != 0)
{
CascReadFile(hFile, szBuffer, sizeof(szBuffer), &dwBytes);
if (dwBytes == 0)
break;
fwrite(szBuffer, 1, dwBytes, fileHandle);
}
if (fileHandle != NULL)
{
fclose(fileHandle);
}
if (hFile != NULL)
{
CascCloseFile(hFile);
}
}
else
{
cout << "*NOT* Extracting file (invalid info!): " << extractedName
<< endl;
}
}
else
{
cout << "Error: CascOpenFile" << endl;
result = false;
}
return result;
}
#endif /* HAVE_CASC */
| 4,367
|
C++
|
.cpp
| 176
| 20.045455
| 133
| 0.630022
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,095
|
UIConsole.cpp
|
Wargus_stargus/src/UIConsole.cpp
|
/*
* UIConsole.cpp
*
* Author: Andreas Volz
*/
// project
#include "UIConsole.h"
#include "Logger.h"
#include "Hurricane.h"
#include "platform.h"
using namespace std;
static Logger logger = Logger("startool.UIConsole");
UIConsole::UIConsole(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane)
{
}
UIConsole::~UIConsole()
{
}
bool UIConsole::convert(Storage pngfile, int left, int right)
{
bool result = true;
string complete_file = pngfile.getFullPath() + ".png";
string left_file = pngfile.getFullPath() + "_left.png";
string right_file = pngfile.getFullPath() + "_right.png";
string middle_file = pngfile.getFullPath() + "_middle.png";
string tmp_file = pngfile.getFullPath() + "_tmp.png";
// fix resolution for SC1, in case of Remastered this has to be an option
int width = 640;
int height = 480;
string wxh = to_string(width) + "x" + to_string(height);
int left_abs = width - left;
//echo $left_abs
//convert tconsole.png -crop ${width}x${height}-${left_abs}+0 tconsole_left.png
//convert tconsole.png -crop ${width}x${height}+${right}+0 tconsole_right.png
string convert_left_cmd = "convert \"" + complete_file + "\" -crop " + wxh + "-" + to_string(left_abs) + "+0 \"" + left_file + "\"";
string convert_right_cmd = "convert \"" + complete_file + "\" -crop " + wxh + "+" + to_string(right) + "+0 \"" + right_file + "\"";
LOG4CXX_DEBUG(logger, convert_left_cmd);
LOG4CXX_DEBUG(logger, convert_right_cmd);
if(result)
{
result = callConvert(convert_left_cmd);
}
if(result)
{
result = callConvert(convert_right_cmd);
}
int middle = right - left;
//echo $middle
int left_tmp = left_abs - middle;
int middle_abs = right - middle;
//echo $left_tmp
//convert tconsole.png -crop ${width}x${height}-${left_tmp}+0 tmp.png
//convert tmp.png -crop ${width}x${height}+${middle_abs}+0 tconsole_middle.png
string convert_tmp_cmd = "convert \"" + complete_file + "\" -crop " + wxh + "-" + to_string(left_tmp) + "+0 \"" + tmp_file + "\"";
string convert_middle_cmd = "convert \"" + tmp_file + "\" -crop " + wxh + "+" + to_string(middle_abs) + "+0 \"" + middle_file + "\"";
LOG4CXX_DEBUG(logger, convert_tmp_cmd);
LOG4CXX_DEBUG(logger, convert_middle_cmd);
if(result)
{
result = callConvert(convert_tmp_cmd);
}
if(result)
{
result = callConvert(convert_middle_cmd);
}
fs::remove(tmp_file);
return result;
}
bool UIConsole::callConvert(const std::string &cmd)
{
bool result = true;
// try convert with ImageMagick 7+
string magic7_cmd("magick " + cmd);
int sys_call = system(magic7_cmd.c_str());
if (sys_call != 0)
{
// try convert with ImageMagick <= 6
string magic6_cmd(cmd);
sys_call = system(magic6_cmd.c_str());
if (sys_call != 0)
{
// try convert with GraphicsMagick
string gm_cmd("gm " + cmd);
sys_call = system(gm_cmd.c_str());
if (sys_call != 0)
{
result = false;
}
}
}
return result;
}
| 3,013
|
C++
|
.cpp
| 93
| 29.064516
| 135
| 0.645596
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,096
|
FileUtil.cpp
|
Wargus_stargus/src/FileUtil.cpp
|
/*
* FileUtil.cpp
*
* Author: Andreas Volz
*/
// project
#include "FileUtil.h"
// system
#include <sys/types.h>
#include <sys/stat.h>
using namespace std;
bool FileExists(const std::string &filename)
{
struct stat buffer;
return stat(filename.c_str(), &buffer) == 0 ? true : false;
}
void CheckPath(const std::string &path)
{
CheckPath(path.c_str());
}
void CheckPath(const char *path)
{
char *cp = NULL;
char *s = NULL;
cp = platform::strdup(path);
s = strrchr(cp, '/');
if (s)
{
*s = '\0'; // remove file
s = cp;
for (;;)
{
// make each path element
s = strchr(s, '/');
if (s)
{
*s = '\0';
}
platform::mkdir(cp, 0777);
if (s)
{
*s++ = '/';
}
else
{
break;
}
}
}
free(cp);
}
| 833
|
C++
|
.cpp
| 51
| 12.372549
| 61
| 0.529107
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,097
|
PaletteImage.cpp
|
Wargus_stargus/src/PaletteImage.cpp
|
/*
* PaletteImage.cpp
*
* Author: Andreas Volz
*/
// project
#include "PaletteImage.h"
// system
#include <iostream>
#include <math.h>
using namespace std;
PaletteImage::PaletteImage(const DataChunk &datachunk, const Size &size) :
mData(datachunk.getDataPointer(), datachunk.getDataPointer()+datachunk.getSize()),
mSize(size)
{
}
PaletteImage::PaletteImage(const Size &size) :
mData(size.getWidth() * size.getHeight(), 0),
mSize(size)
{
}
PaletteImage::~PaletteImage()
{
}
const unsigned char* PaletteImage::getRawDataPointer() const
{
return mData.data();
}
size_t PaletteImage::positionToIndex(const Pos &pos) const
{
size_t data_pos = 0;
// if pos is outside image return just 0 as fail safe
if((pos.getX() < mSize.getWidth()) || (pos.getY() < mSize.getHeight()) || (pos.getX() > 0) || (pos.getY() > 0))
{
data_pos = (pos.getY() * mSize.getWidth()) + pos.getX();
}
return data_pos;
}
const Pos PaletteImage::indexToPosition(size_t index) const
{
int y = 0;
int x = 0;
// if index is out of data size that return Pos(0, 0) as fail safe
if(index < mData.size())
{
y = index / mSize.getWidth();
x = index % mSize.getWidth();
}
return Pos(x, y);
}
const Size PaletteImage::getSize() const
{
return mSize;
}
unsigned char &PaletteImage::at(const Pos &pos)
{
return at(positionToIndex(pos));
}
const unsigned char &PaletteImage::at(const Pos &pos) const
{
return at(positionToIndex(pos));
}
unsigned char &PaletteImage::at(size_t pos)
{
return mData.at(pos);
}
const unsigned char &PaletteImage::at(size_t pos) const
{
return mData.at(pos);
}
void PaletteImage::fill(unsigned char color_index)
{
for(unsigned int i = 0; i < mData.size(); i++)
{
mData.at(i) = color_index;
}
}
bool PaletteImage::operator== (const PaletteImage& image_cmp)
{
// if the same object
if (this == &image_cmp)
{
return true;
}
// if the size isn't the same no content needs to be checked
if(image_cmp.getSize() != this->getSize())
{
return false;
}
// compare the content of the pixel data
if(image_cmp.mData == this->mData)
{
return true;
}
return false;
}
| 2,174
|
C++
|
.cpp
| 96
| 20.208333
| 113
| 0.690732
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,098
|
Hurricane.cpp
|
Wargus_stargus/src/Hurricane.cpp
|
/*
* Hurricane.cpp
*
* Author: Andreas Volz
*/
// Local
#include "Hurricane.h"
// Sytsem
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
Hurricane::Hurricane()
{
}
Hurricane::~Hurricane()
{
}
std::shared_ptr<DataChunk> Hurricane::extractDataChunk(const std::string &archivedFile)
{
size_t bufferLen = 0;
unsigned char *szEntryBufferPrt = nullptr;
if (extractMemory(archivedFile, &szEntryBufferPrt, &bufferLen))
{
shared_ptr<DataChunk> data = make_shared<DataChunk>(&szEntryBufferPrt,
bufferLen);
return data;
}
return nullptr;
}
std::shared_ptr<std::istream> Hurricane::extractStream(const std::string &archivedFile)
{
size_t bufferLen = 0;
unsigned char *szEntryBufferPrt = nullptr;
if (extractMemory(archivedFile, &szEntryBufferPrt, &bufferLen))
{
shared_ptr<stringstream> sstream = make_shared<stringstream>();
// write the memory into the stream
sstream->write(reinterpret_cast<char*>(szEntryBufferPrt), bufferLen);
// and then free the memory afterwards
free(szEntryBufferPrt);
return sstream;
}
return nullptr;
}
const std::string &Hurricane::getArchiveName() const
{
return mArchiveName;
}
| 1,244
|
C++
|
.cpp
| 49
| 22.102041
| 87
| 0.726655
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,099
|
Palette.cpp
|
Wargus_stargus/src/Palette.cpp
|
/*
* Palettes.cpp
*
* Author: Andreas Volz
*/
// project
#include <Palette.h>
#include "Logger.h"
#include "NoValidPaletteException.h"
// system
#include <iostream>
#include <fstream>
using namespace std;
static Logger logger = Logger("startool.Palette");
Palette::Palette()
{
}
Palette::Palette(std::shared_ptr<DataChunk> rawPalette)
{
load(rawPalette);
}
Palette::~Palette()
{
}
void Palette::load(std::shared_ptr<DataChunk> rawPalette)
{
if(rawPalette->getSize() == 256 * 4) // RGBx/WPE size type
{
for(unsigned int i = 0; i < rawPalette->getSize(); i += 4)
{
unsigned char red = rawPalette->at(i);
unsigned char green = rawPalette->at(i+1);
unsigned char blue = rawPalette->at(i+2);
// ignore the 4th component, as it is not used as alpha
Color rgb(red, green, blue);
at(i/4) = rgb;
}
}
else if(rawPalette->getSize() == 256 * 3) // RGB size type
{
for(unsigned int i = 0; i < rawPalette->getSize(); i += 3)
{
unsigned char red = rawPalette->at(i);
unsigned char green = rawPalette->at(i+1);
unsigned char blue = rawPalette->at(i+2);
Color rgb(red, green, blue);
at(i/3) = rgb;
}
}
else
{
throw NoValidPaletteException(rawPalette->getSize());
}
}
std::shared_ptr<DataChunk> Palette::createDataChunk()
{
std::shared_ptr<DataChunk> datachunk = make_shared<DataChunk>();
for(auto color_it = mColorPalette.begin(); color_it < mColorPalette.end(); color_it++)
{
Color &rgb = *color_it;
unsigned char red = rgb.getRed();
unsigned char green = rgb.getGreen();
unsigned char blue = rgb.getBlue();
datachunk->addData(&red, 1);
datachunk->addData(&green, 1);
datachunk->addData(&blue, 1);
}
return datachunk;
}
Color &Palette::at(unsigned int index)
{
return mColorPalette.at(index);
}
| 1,859
|
C++
|
.cpp
| 73
| 22.068493
| 88
| 0.661391
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,100
|
Converter.cpp
|
Wargus_stargus/src/Converter.cpp
|
/*
* Converter.cpp
*
* Author: Andreas Volz
*/
#include "Converter.h"
Converter::Converter(std::shared_ptr<Hurricane> hurricane) :
mHurricane(hurricane)
{
}
Converter::~Converter()
{
}
| 202
|
C++
|
.cpp
| 13
| 13.615385
| 60
| 0.715847
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,101
|
Scm.cpp
|
Wargus_stargus/src/Scm.cpp
|
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
/**@name Scm.cpp - The scm. */
//
// (c) Copyright 2002-2007 by Jimmy Salmon
//
// This program 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; version 2 dated June, 1991.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// $Id$
//@{
// Lcoal
#include "Scm.h"
#include "Chk.h"
#include "Hurricane.h"
#include "endian.h"
#include "FileUtil.h"
#include "Storm.h"
#include "platform.h"
// System
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <vector>
#include <string>
using namespace std;
Scm::Scm(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane)
{
}
Scm::~Scm()
{
}
bool Scm::convert(const std::string &arcfile, const std::vector<std::string> &unitNames, Storage storage)
{
bool result = true;
string scm_path = storage.getFullPath() + "scm";
result = mHurricane->extractFile(arcfile, scm_path);
if (result)
{
// call the Chk converter with temp file...
shared_ptr<Storm> storm = make_shared<Storm>(scm_path);
Chk chk(storm);
chk.setUnitNames(unitNames);
result = chk.convert("staredit\\scenario.chk", storage.getFullPath());
// delete the temporary .chk file -> below don't access 'breeze' any more!
platform::unlink(scm_path);
}
return result;
}
| 2,492
|
C++
|
.cpp
| 72
| 32.847222
| 105
| 0.553342
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,102
|
KaitaiConverter.cpp
|
Wargus_stargus/src/KaitaiConverter.cpp
|
/*
* KaitaiConverter.cpp
*
* Author: Andreas Volz
*/
// project
#include "KaitaiConverter.h"
#include "DataChunk.h"
#include "Hurricane.h"
// system
#include <iostream>
using namespace std;
KaitaiConverter::KaitaiConverter(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane)
{
}
KaitaiConverter::~KaitaiConverter()
{
}
/*std::shared_ptr<kaitai::kstream> KaitaiConverter::getKaitaiStream(const std::string &file)
{
std::shared_ptr<std::istream> stream = mHurricane->extractStream(file);
std::string s;
std::ostringstream os;
os<<stream->rdbuf();
s=os.str();
std::shared_ptr<kaitai::kstream> ks = make_shared<kaitai::kstream>(s);
return ks;
}*/
| 688
|
C++
|
.cpp
| 29
| 21.655172
| 92
| 0.739198
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,103
|
AbstractPalette.cpp
|
Wargus_stargus/src/AbstractPalette.cpp
|
/*
* AbstractPalette.cpp
*
* Author: Andreas Volz
*/
#include "AbstractPalette.h"
#include "Palette.h"
#include "Palette2D.h"
#include "NoValidPaletteException.h"
using namespace std;
AbstractPalette::~AbstractPalette()
{
}
bool AbstractPalette::write(const std::string &filename)
{
bool result = true;
std::shared_ptr<DataChunk> dc_pal = createDataChunk();
result = dc_pal->write(filename);
return result;
}
bool AbstractPalette::read(const std::string &filename)
{
bool result = true;
std::shared_ptr<DataChunk> dc_pal = make_shared<DataChunk>();
result = dc_pal->read(filename);
if(result)
{
load(dc_pal);
}
return result;
}
std::shared_ptr<AbstractPalette> AbstractPalette::create(std::shared_ptr<DataChunk> rawPalette)
{
if((rawPalette->getSize() == 256 * 3) || (rawPalette->getSize() == 256 * 3)) // RGBx/WPE size type
{
return make_shared<Palette>(rawPalette);
}
else if(!(rawPalette->getSize() % (256 * 3))) // PCX2D size type (size 3 and 4 are yet in the if statement)
{
return make_shared<Palette2D>(rawPalette);
}
// no valid palette
throw NoValidPaletteException(rawPalette->getSize());
// will never go here...
return nullptr;
}
| 1,218
|
C++
|
.cpp
| 46
| 23.934783
| 109
| 0.711821
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,104
|
stargus.cpp
|
Wargus_stargus/src/stargus.cpp
|
/*
stargus.c - Start game engine Stratagus with Stargus data
Copyright (C) 2010-2012 Pali Roh√°r <pali.rohar@gmail.com>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#define GAME_NAME "Stargus"
#define GAME_CD "Starcraft CD or installation stardat.mpq or starcraft.mpq file"
#define GAME_CD_FILE_PATTERNS "install.exe", "Install.exe", "stardat.mpq", "StarDat.mpq", "starcraft.mpq", "StarCraft.mpq"
#define GAME "stargus"
#define EXTRACTOR_TOOL "startool"
#define EXTRACTOR_ARGS {"-v -s", NULL}
#define CHECK_EXTRACTED_VERSION 1
// configure here which files/directories will be copied from stargus (e.g. contrib)
#define CONTRIB_DIRECTORIES { "mpqlist.txt", "mpqlist.txt", \
"contrib/fog.png", "graphics/tilesets/fog.png", \
"contrib/transparent.png", "graphics/ui/transparent.png", \
"scripts", "scripts", NULL }
const char *SRC_PATH()
{
std::cout << "sourcedir:" << SOURCE_DIR << std::endl;
return SOURCE_DIR;
}
// I still have hope some far day someone will fix this annoying warnings... ->
#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wformat-overflow="
#else
#define WIN32 1
#endif
#include "stratagus-game-launcher.h"
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif
// <-
| 2,010
|
C++
|
.cpp
| 47
| 40.659574
| 122
| 0.758568
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,105
|
luagen.cpp
|
Wargus_stargus/src/luagen.cpp
|
/*
* luagen.cpp
*
* Author: Andreas Volz
*/
#include <luagen.h>
using namespace std;
namespace lg {
std::string boolean(bool b)
{
return b ? "true" : "false";
}
std::string integer(int i)
{
return to_string(i);
}
std::string function(const std::string &name, const std::initializer_list<std::string> &functionParams)
{
return function(name, params(functionParams));
}
std::string function(const std::string &name, const std::string &functionParams)
{
string func_str(name + "(");
func_str += functionParams;
func_str += ")";
return func_str;
}
std::string table(const std::initializer_list<std::string> &tableElements)
{
return table(params(tableElements));
}
std::string table(const std::string &content)
{
string table_str("{");
table_str += content;
table_str += "}";
return table_str;
}
std::string assign(const std::string &left, const std::string &right)
{
string assign_str(left + " = " + right);
return assign_str;
}
std::string compare(const std::string &left, const std::string &right)
{
string compare_str(left + " == " + right);
return compare_str;
}
std::string quote(const std::string &text)
{
string quote_str("\"");
quote_str += text;
quote_str += "\"";
return quote_str;
}
std::string singleQuote(const std::string &text)
{
string quote_str("'");
quote_str += text;
quote_str += "'";
return quote_str;
}
std::string params(const std::initializer_list<std::string> ¶ms_init_list)
{
return params(params_init_list.begin(), params_init_list.end());
}
std::string params(const std::vector<std::string> ¶ms_vector)
{
return params(params_vector.begin(), params_vector.end());
}
std::string paramsQuote(const std::initializer_list<std::string> ¶ms_init_list)
{
return paramsQuote(params_init_list.begin(), params_init_list.end());
}
std::string paramsQuote(const std::vector<std::string> ¶ms_vector)
{
return paramsQuote(params_vector.begin(), params_vector.end());
}
std::string line(const std::string &str)
{
return string(str + '\n');
}
std::string sizeTable(const Size &s)
{
return table({to_string(s.getWidth()), to_string(s.getHeight())});
}
std::string posTable(const Pos &p)
{
return table({to_string(p.getX()), to_string(p.getY())});
}
std::string DefineUnitType(const std::string &id, const std::string &unitTable)
{
return function("DefineUnitType", {quote(id), unitTable});
}
std::string DefineUnitType(const std::string &id, const std::initializer_list<std::string> &tableElements)
{
return DefineUnitType(id, table(tableElements));
}
std::string CreateUnit(const std::string &id, int playerID, const Pos &pos)
{
return function("CreateUnit", {quote(id), to_string(playerID), posTable(pos)});
}
std::string DefineTileset(const std::string &name, const std::string &image, const std::initializer_list<std::string> &slotsTable)
{
return function("DefineTileset", {quote("name"), quote(name), quote("size"), table({"32", "32"}), quote("image"), quote(image), quote("slots"), table(slotsTable)});
}
std::string tilesetSlotEntry(const std::string &type, const std::initializer_list<std::string> &propertiesQuotedParams, const std::initializer_list<std::string> &tilesTable)
{
return params({quote(type), table({paramsQuote(propertiesQuotedParams), table(tilesTable)})});
}
std::string tilesetSlotEntryNonMix(const std::string &type, const std::initializer_list<std::string> &propertiesQuotedParams, const std::initializer_list<std::string> &tilesTable)
{
return params({quote(type), table({paramsQuote(propertiesQuotedParams), table(tilesTable)})});
}
} /* namespace lg */
| 3,624
|
C++
|
.cpp
| 115
| 29.547826
| 179
| 0.72267
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,106
|
startool.cpp
|
Wargus_stargus/src/startool.cpp
|
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Utility for Stratagus - A free fantasy real time strategy game engine
//
/**@name startool.c - Extract files from star archives. */
//
// (c) Copyright 2002-2012 by Jimmy Salmon and Pali Roh√°r
//
// This program 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; version 2 dated June, 1991.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
// project
#include <UnitsConverter.h>
#include <PortraitsConverter.h>
#include "dat/DataHub.h"
#include "tileset/TilesetHub.h"
#include "PngExporter.h"
#include "Smacker.h"
#include "Palette.h"
#include "endian.h"
#include "startool.h"
#include "Preferences.h"
#include "Scm.h"
#include "FileUtil.h"
#include "Pcx.h"
#include "Font.h"
#include "Grp.h"
#include "Panel.h"
#include "Widgets.h"
#include "DataChunk.h"
#include "Casc.h"
#include "Dds.h"
#include "Logger.h"
#include "Breeze.h"
#include "Storage.h"
#include "Wav.h"
#include "tileset/TilesetHub.h"
#include "platform.h"
#include "UIConsole.h"
#include "StringUtil.h"
#include "pacman.h"
#include "ImagesConverter.h"
#include "SfxConverter.h"
#include "optparser.h"
// system
#include <nlohmann/json.hpp>
#include <fstream>
#include <map>
using json = nlohmann::json;
// <-
// System
#include <memory>
#include <map>
// activate local debug messages
#define DEBUG 1
using namespace std;
static Logger logger("startool.main");
// test only
void testHook();
bool dev_hack = false;
//----------------------------------------------------------------------------
/**
** Raw extraction
**
** @param arcfile File identifier in the MPQ file
** @param file Place to save the file on the drive (relative)
*/
bool RawExtract(std::shared_ptr<Hurricane> hurricane, const char *arcfile, Storage storage)
{
bool result = true;
result = hurricane->extractFile(arcfile, storage.getFullPath(), false);
return result;
}
void CreatePanels()
{
Panel panel;
panel.save(264, 288);
panel.save(384, 256);
panel.save(312, 312);
panel.save(288, 128);
panel.save(296, 336);
}
bool CheckCASCDataFolder(const std::string &dir)
{
return FileExists(dir + "/.build.info");
}
//----------------------------------------------------------------------------
// Main loop
//----------------------------------------------------------------------------
/** option parser **/
struct Arg: public option::Arg
{
static void printError(const char *msg1, const option::Option &opt, const char *msg2)
{
fprintf(stderr, "%s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(const option::Option &option, bool msg)
{
if (msg)
printError("Unknown option '", option, "'\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(const option::Option &option, bool msg)
{
if (option.arg != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires an argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus NonEmpty(const option::Option &option, bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a non-empty argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(const option::Option &option, bool msg)
{
char *endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10))
{
};
if (endptr != option.arg && *endptr == 0)
return option::ARG_OK;
if (msg)
printError("Option '", option, "' requires a numeric argument\n");
return option::ARG_ILLEGAL;
}
};
enum optionIndex
{
UNKNOWN, HELP, VIDEO, SOUND, VERSIONPARAM, DEV
};
const option::Descriptor usage[] =
{
{
UNKNOWN, 0, "", "", option::Arg::None, "USAGE: startool archive-directory [destination-directory]\n\n"
"Options:"
},
{ HELP, 0, "h", "help", option::Arg::None, " --help, -h \t\tPrint usage and exit" },
{ VIDEO, 0, "v", "video", Arg::None, " --video, -v \t\tExtract and convert videos" },
{ SOUND, 0, "s", "sound", Arg::None, " --sound, -s \t\tExtract and convert sounds" },
{ DEV, 0, "d", "dev", Arg::None,
" --dev, -d \t\tSome test hooks while development. Don't use it if you don't know what it does!"},
{ VERSIONPARAM, 0, "V", "version", Arg::None, " --version, -V \t\tShow version" },
{
UNKNOWN, 0, "", "", option::Arg::None,
"\narchive-directory \t\tDirectory which include the archive install.exe or stardat.mpq...\n"
"destination-directory \t\tDirectory where the extracted files are placed.\n"
},
{ 0, 0, 0, 0, 0, 0 }
};
int parseOptions(int argc, const char **argv)
{
Preferences &preferences = Preferences::getInstance();
argc -= (argc > 0);
argv += (argc > 0); // skip program name argv[0] if present
option::Stats stats(usage, argc, argv);
std::unique_ptr<option::Option[]> options(new option::Option[stats.options_max]), buffer(new option::Option[stats.buffer_max]);
option::Parser parse(usage, argc, argv, options.get(), buffer.get());
if (parse.error())
exit(0);
if (options[HELP])
{
option::printUsage(std::cout, usage);
exit(0);
}
// parse options
if (options[VIDEO].count() > 0)
{
preferences.setVideoExtraction(true);
}
if (options[SOUND].count() > 0)
{
preferences.setSoundExtraction(true);
}
if (options[DEV].count() > 0)
{
testHook();
}
if (options[VERSIONPARAM].count() > 0)
{
printf(VERSION "\n");
exit(0);
}
for (option::Option *opt = options[UNKNOWN]; opt; opt = opt->next())
std::cout << "Unknown option: " << opt->name << "\n";
for (int i = 0; i < parse.nonOptionsCount(); ++i)
{
switch (i)
{
case 0:
cout << "archive-directory #" << i << ": " << parse.nonOption(i) << "\n";
preferences.setArchiveDir(parse.nonOption(i));
break;
case 1:
cout << "destination-directory #" << i << ": " << parse.nonOption(i) << "\n";
preferences.setDestDir(parse.nonOption(i));
break;
default:
break;
}
}
if (preferences.getArchiveDir().empty())
{
cerr << "Error: 'archive-directory' not given!" << endl << endl;
option::printUsage(std::cout, usage);
exit(1);
}
return 0;
}
void loadPalettes(std::shared_ptr<Hurricane> hurricane,
Storage palStorage,
std::map<std::string, std::shared_ptr<AbstractPalette>> &paletteMap)
{
// read in the json file
std::ifstream json_file(pacman::searchFile("dataset/palettes.json"));
json palettes_json; //create unitiialized json object
json_file >> palettes_json; // initialize json object with what was read from file
//std::cout << units_json << std::endl; // prints json object to screen
vector<string> wpeNames;
/** WPE **/
auto &wpe_section = palettes_json.at("WPE");
for(auto &wpe_array : wpe_section)
{
string name = wpe_array.at("name");
string wpe_arcfile = wpe_array.at("arcfile");
string pal_palette = wpe_array.at("palette");
shared_ptr<DataChunk> dataWPE = hurricane->extractDataChunk(wpe_arcfile);
if (dataWPE) // load from WPE palette
{
shared_ptr<Palette> pal = make_shared<Palette>(dataWPE);
paletteMap[name] = pal;
wpeNames.push_back(name);
string pal_file(palStorage.getFullPath() + pal_palette);
CheckPath(pal_file);
pal->write(pal_file);
}
else // load from stored .pal palette
{
Breeze localPal(palStorage.getFullPath());
shared_ptr<DataChunk> dataPal = localPal.extractDataChunk(pal_palette);
if(dataPal)
{
std::shared_ptr<Palette> pal = make_shared<Palette>(dataPal);
paletteMap[name] = pal;
}
}
//cout << wpe_array << endl;
}
/** PCX **/
auto &pcx_section = palettes_json.at("PCX");
for(auto &pcx_array : pcx_section)
{
string name = pcx_array.at("name");
string pcx_arcfile = pcx_array.at("arcfile");
string pal_palette = pcx_array.at("palette");
Pcx pcx(hurricane, pcx_arcfile);
if(!pcx.getSize().isEmpty()) // load from PCX palette
{
std::shared_ptr<Palette> pal;
try
{
auto &pcx_mapping = pcx_array.at("mapping");
int length = pcx_mapping.at("length");
int start = pcx_mapping.at("start");
int index = pcx_mapping.at("index");
pal = pcx.mapIndexPalette(length, start, index);
}
catch (const nlohmann::detail::out_of_range &json_range)
{
pal = pcx.getPalette();
}
string pal_file(palStorage.getFullPath() + pal_palette);
CheckPath(pal_file);
pal->write(pal_file);
paletteMap[name] = pal;
}
else // load from stored .pal palette
{
Breeze localPal(palStorage.getFullPath());
shared_ptr<DataChunk> dataPal = localPal.extractDataChunk(pal_palette);
if(dataPal)
{
std::shared_ptr<Palette> pal = make_shared<Palette>(dataPal);
paletteMap[name] = pal;
}
}
//cout << pcx_array << endl;
}
/** PCX2D (after WPE block has been read in) **/
auto &pcx2d_section = palettes_json.at("PCX2D");
for(auto &pcx_array : pcx2d_section)
{
string pcx_name = pcx_array.at("name");
string pcx_arcfile = pcx_array.at("arcfile");
string pal_palette = pcx_array.at("palette");
// replace this with the first of the WPE palettes. Which one doesn't care for the palette logic.
replaceString("<?>", *wpeNames.begin(), pcx_arcfile);
Pcx pcx(hurricane, pcx_arcfile);
std::shared_ptr<Palette2D> pal2D = pcx.map2DPalette();
string pal_file(palStorage.getFullPath() + pal_palette);
CheckPath(pal_file);
pal2D->write(pal_file);
paletteMap[pcx_name] = pal2D;
//cout << pcx_array << endl;
}
}
/**
* The only purpose of this function is to have a hook to develop/test single functions and then exit
*/
void testHook()
{
LOG4CXX_DEBUG(logger, "testHook()");
/*string font_path = "/home/andreas/src/git/stargus/work_font/classic/files/font/";
string font_path_rm = "/home/andreas/src/git/stargus/work_font/remastered/SD/font/";
string font_path_hd = "/home/andreas/src/git/stargus/work_font/remastered/font/"; // problem!
shared_ptr<Breeze> breeze = make_shared<Breeze>(font_path_rm);
Font font(breeze);
font.convert("font16.fnt", "font16");*/
shared_ptr<Storm> storm = make_shared<Storm>("/home/andreas/Games/DOS/Starcraft/Original_Backup/starcraft_install.exe_MPQ/files/stardat.mpq");
//shared_ptr<Storm> storm = make_shared<Storm>("/home/andreas/Games/DOS/Starcraft/Original_Backup/broodwar_install.exe_MPQ/files/broodat.mpq");
//shared_ptr<Breeze> breeze = make_shared<Breeze>("/home/andreas/Games/DOS/Starcraft/Original_Backup/starcraft_install.exe_MPQ");
dat::DataHub datahub(storm);
dat::Unit unit(datahub, 0, "test");
cout << "unit: " << unit.name_tbl().name1() << endl;
dat::IScript is = unit.flingy_obj().sprite_obj().image_obj().iscript_obj();
int animation_count = is.getAnimationCount();
cout << "animation_count: " << to_string(animation_count) << endl;
for(int i = 0; i < animation_count; i++)
//int i = 8;
{
cout << "animation: " << i << endl;
std::vector<iscript_bin_t::opcode_type_t*> opcode_vec =
unit.flingy_obj().sprite_obj().image_obj().iscript_obj().getAnimationScript(i);
for(auto opcode : opcode_vec)
{
cout << "code: " << hex << opcode->code() << endl;
}
}
dat::Sfx sfx = unit.ready_sound_obj();
sfx.sound_file_tbl();
dat::Portrait portrait = unit.portrait_obj();
portrait.video_talking_tbl();
portrait.video_idle_tbl();
/// Image 1
Pcx pcx1(storm, "game\\tunit.pcx");
pcx1.savePNG("/tmp/tunit.png");
std::shared_ptr<Palette> pal = pcx1.mapIndexPalette(8, 8, 2);
pal->createDataChunk()->write("/tmp/tunit.pal");
// Image 2
Pcx pcx2(storm, "unit\\cmdbtns\\ticon.pcx");
pcx2.savePNG("/tmp/ticon.png");
std::shared_ptr<Palette> pal2 = pcx2.mapIndexPalette(16, 0, 0);
pal2->createDataChunk()->write("/tmp/ticon.pal");
// Image 3
Pcx pcx3(storm, "tileset\\ashworld\\ofire.pcx");
pcx3.savePNG("/tmp/ofire.png");
std::shared_ptr<Palette2D> pal2D_3 = pcx3.map2DPalette();
std::shared_ptr<Palette> pal3 = pcx3.getPalette();
pal3->createDataChunk()->write("/tmp/ofire.pal");
// Image 4
Pcx pcx4(storm, "tileset\\ashworld\\ofire.pcx");
pcx4.savePNG("/tmp/bfire.png");
std::shared_ptr<Palette2D> pal2D_4 = pcx4.map2DPalette();
std::shared_ptr<Palette> pal4 = pcx4.getPalette();
pal4->createDataChunk()->write("/tmp/ofire.pal");
pal2D_4->write("/tmp/ofire.pal2d");
shared_ptr<DataChunk> terrainWPE = storm->extractDataChunk("tileset\\jungle.wpe");
shared_ptr<Palette> terrainPalette = make_shared<Palette>(terrainWPE);
terrainPalette->createDataChunk()->write("/tmp/terrainPalette.pal");
//string grp_file = "unit\\protoss\\pbaGlow.grp";
string grp_file = "unit\\thingy\\ofirec.grp";
Grp grp(storm, grp_file);
grp.setPalette(pal2D_4);
grp.setRGBA(true);
//grp.setPalette(terrainPalette);
//grp.setTransparent(200);
//grp.setRGBA(true);
// read in the json file
std::ifstream json_file(pacman::searchFile("dataset/dlgs_race.json"));
json dlgsRaceJson; //create unitiialized json object
json_file >> dlgsRaceJson; // initialize json object with what was read from file
Widgets widgets(storm);
widgets.setPalette(pal);
widgets.convert("dlgs\\terran.grp", "/tmp/widgets2/", dlgsRaceJson);
grp.save("/tmp/ofirec.png");
cout << "end testHook()" << endl;
exit(0);
}
/**
** Main
*/
int main(int argc, const char **argv)
{
#ifdef HAVE_LOG4CXX
if (FileExists("logging.prop"))
{
log4cxx::PropertyConfigurator::configure("logging.prop");
}
else
{
logger.off();
}
#endif // HAVE_LOG4CXX
unsigned u;
char buf[8192] =
{ '\0' };
int i;
FILE *f;
Preferences &preferences = Preferences::getInstance();
preferences.init(); // initialize all properties once in the beginning of the application
parseOptions(argc, argv);
LOG4CXX_INFO(logger, "Application start");
sprintf(buf, "%s/extracted", preferences.getDestDir().c_str());
f = fopen(buf, "r");
if (f)
{
char version[20];
int len = 0;
if (fgets(version, 20, f))
len = 1;
fclose(f);
if (len != 0 && strcmp(version, VERSION) == 0)
{
printf("Note: Data is already extracted in Dir \"%s\" with this version of startool\n", preferences.getDestDir().c_str());
fflush(stdout);
}
}
printf("Extract from \"%s\" to \"%s\"\n", preferences.getArchiveDir().c_str(), preferences.getDestDir().c_str());
printf("Please be patient, the data may take a couple of minutes to extract...\n\n");
fflush(stdout);
// set this to false for activating the SC remastered Casc code while development
bool mpq = true;
Storage graphics;
graphics.setDataPath(preferences.getDestDir());
graphics.setDataType("graphics");
Storage videos;
videos.setDataPath(preferences.getDestDir());
videos.setDataType("videos");
Storage fonts;
fonts.setDataPath(preferences.getDestDir());
fonts.setDataType("graphics/ui/fonts");
Storage sounds;
sounds.setDataPath(preferences.getDestDir());
sounds.setDataType("sounds");
Storage tilesets;
tilesets.setDataPath(preferences.getDestDir());
tilesets.setDataType("graphics/tilesets");
Storage luagen;
luagen.setDataPath(preferences.getDestDir());
luagen.setDataType("luagen");
Storage palStorage;
palStorage.setDataPath(preferences.getDestDir());
palStorage.setDataType("palette");
Storage data;
data.setDataPath(preferences.getDestDir());
map<string, shared_ptr<AbstractPalette>> paletteMap;
if (mpq)
{
Control *c = nullptr;
unsigned int len = 0;
bool case_func = false;
shared_ptr<Storm> main_storm;
shared_ptr<Storm> sub_storm;
shared_ptr<Storm> storm;
c = CDTodo_bootstrap;
len = sizeof(CDTodo_bootstrap) / sizeof(*CDTodo_bootstrap);
for (u = 0; u < len; ++u)
{
switch (c[u].Type)
{
case F:
{
string archiveFile = preferences.getArchiveDir() + "/" + c[u].ArcFile;
case_func = FileExists(archiveFile);
cout << "F: " << c[u].ArcFile << " : " << c[u].File << " : " << case_func << endl;
if (case_func && !main_storm)
{
main_storm = make_shared<Storm>(archiveFile);
}
}
break;
case Q:
{
cout << "Q:" << c[u].ArcFile << " : " << c[u].File << endl;
if (main_storm)
{
string file = preferences.getDestDir() + "/" + c[u].File;
main_storm->extractFile(c[u].ArcFile, file, false);
}
}
break;
default:
break;
}
}
c = Todo_bootstrap;
len = sizeof(Todo_bootstrap) / sizeof(*Todo_bootstrap);
for (u = 0; u < len; ++u)
{
switch (c[u].Type)
{
case F:
{
string archiveFile = preferences.getDestDir() + "/" + c[u].ArcFile;
case_func = FileExists(archiveFile);
cout << "F: " << c[u].ArcFile << " : " << c[u].File << " : " << case_func << endl;
if (case_func && !sub_storm)
{
sub_storm = make_shared<Storm>(archiveFile);
}
}
break;
default:
break;
}
}
dat::DataHub datahub(sub_storm);
// read in the json file
std::ifstream json_file(pacman::searchFile("dataset/units.json"));
json units_json; //create unitiialized json object
json_file >> units_json; // initialize json object with what was read from file
//std::cout << units_json << std::endl; // prints json object to screen
vector<string> unitNames;
for(auto &array : units_json)
{
string unit_name = array.at("name");
unitNames.push_back(unit_name);
}
loadPalettes(sub_storm, palStorage, paletteMap);
if (preferences.getVideoExtraction())
{
PortraitsConverter portraitsConverter(sub_storm, datahub);
portraitsConverter.convert();
}
dat::UnitsConverter unitsConverter(sub_storm, datahub);
unitsConverter.convert(units_json);
ImagesConverter imagesConverter(sub_storm, datahub);
imagesConverter.convert(paletteMap);
if(preferences.getSoundExtraction())
{
SfxConverter sfxConverter(sub_storm, datahub);
sfxConverter.convert();
}
// read in the json file
std::ifstream dlgsRaceJsonStream(pacman::searchFile("dataset/dlgs_race.json"));
json dlgsRaceJson; //create unitiialized json object
dlgsRaceJsonStream >> dlgsRaceJson; // initialize json object with what was read from file
Widgets widgets(sub_storm);
widgets.setPalette(paletteMap["tunit"]);
widgets.convert("dlgs\\terran.grp", graphics("ui/terran"), dlgsRaceJson);
widgets.convert("dlgs\\zerg.grp", graphics("ui/zerg"), dlgsRaceJson);
widgets.convert("dlgs\\protoss.grp", graphics("ui/protoss"), dlgsRaceJson);
for (i = 0; i <= 1; ++i)
{
switch (i)
{
case 0:
// StarDat.mpq or stardat.mpq from inside files\\stardat.mpq
c = Todo;
len = sizeof(Todo) / sizeof(*Todo);
storm = sub_storm;
break;
case 1:
// CD install.exe renamed to StarCraft.mpq or other main mpq file
c = CDTodo;
len = sizeof(CDTodo) / sizeof(*CDTodo);
storm = main_storm;
break;
}
case_func = false;
for (u = 0; u < len; ++u)
{
switch (c[u].Type)
{
case M: // WORKS!
{
printf("ConvertMap: %s, %s", c[u].File, c[u].ArcFile);
Scm scm(storm);
case_func = scm.convert(c[u].ArcFile, unitNames, data(c[u].File));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case T: // WORKS!
{
printf("ConvertTileset: %s, %s", c[u].File, c[u].ArcFile);
tileset::TilesetHub terrain(storm, c[u].ArcFile);
case_func = terrain.convert(paletteMap.at(c[u].File), tilesets(c[u].File));
string luafile(string("tilesets/") + c[u].File + ".lua");
string pngfile(string("tilesets/") + c[u].File + "/" + c[u].File + ".png");
terrain.generateLua(c[u].File, pngfile, luagen(luafile));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case G: // WORKS!
{
printf("ConvertGfx: %s, %s, %d", c[u].File, c[u].ArcFile, c[u].Arg1);
Grp grp(storm, c[u].ArcFile);
std::shared_ptr<AbstractPalette> pal;
if (c[u].Arg1 == 6)
{
pal = paletteMap.at("twire");
grp.setPalette(pal);
}
else if (c[u].Arg1 == 5)
{
pal = paletteMap.at("ticon-0");
grp.setPalette(pal);
}
else if (c[u].Arg1 == 4)
{
pal = paletteMap.at("ticon-0");
grp.setPalette(pal);
grp.setRGBA(true);
}
else if (c[u].Arg1 == 3)
{
pal = paletteMap.at("ofire");
grp.setPalette(pal);
grp.setRGBA(true);
}
else if (c[u].Arg1 == 2)
{
pal = paletteMap.at("tselect-0");
grp.setPalette(pal);
}
else if (c[u].Arg1 == 1)
{
pal = paletteMap.begin()->second;
grp.setPalette(pal);
}
else // default palette
{
pal = paletteMap.begin()->second;
grp.setPalette(pal);
}
case_func = grp.save(graphics(string(c[u].File) + ".png"));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
/*case I: // WORKS!
{
printf("ConvertWidgets: %s, %s", c[u].File, c[u].ArcFile);
Widgets widgets(storm);
std::shared_ptr<AbstractPalette> pal = paletteMap.at("tunit");
widgets.setPalette(pal);
case_func = widgets.convert(c[u].ArcFile, c[u].File);
printf("...%s\n", case_func ? "ok" : "nok");
}*/
break;
case N: // WORKS!
{
printf("ConvertFont: %s, %s", c[u].File, c[u].ArcFile);
Font font(storm);
std::shared_ptr<AbstractPalette> pal = paletteMap.at("tfontgam");
font.setPalette(pal);
case_func = font.convert(c[u].ArcFile, fonts(string(c[u].File) + ".png"));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case W: // WORKS!
if (preferences.getSoundExtraction())
{
printf("ConvertWav: %s, %s", c[u].File, c[u].ArcFile);
Wav wav(storm);
case_func = wav.convert(c[u].ArcFile, sounds(c[u].File));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case V: // WORKS!
if (preferences.getVideoExtraction())
{
printf("ConvertSmacker: %s, %s", c[u].File, c[u].ArcFile);
Smacker video(storm);
case_func = video.convertOGV(c[u].ArcFile, videos(c[u].File));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case P: // WORKS!
if (preferences.getVideoExtraction())
{
printf("ConvertPortrait: %s, %s", c[u].File, c[u].ArcFile);
Smacker video(storm);
case_func = video.convertMNG(c[u].ArcFile, videos(c[u].File));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case H: // WORKS!
{
printf("ConvertPcx: %s, %s", c[u].File, c[u].ArcFile);
Pcx pcx(storm, c[u].ArcFile);
case_func = pcx.savePNG(graphics(string(c[u].File) + ".png"));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case E: // WORKS
{
printf("Extract text: %s, %s", c[u].File, c[u].ArcFile);
auto chunk = storm->extractDataChunk(c[u].ArcFile);
char *utf8 = iconvISO2UTF8(reinterpret_cast<char*>(chunk->getDataPointer()));
if (utf8) {
chunk->replaceData(reinterpret_cast<unsigned char*>(utf8), strlen(utf8), 0);
free(utf8);
case_func = chunk->write(data(c[u].File).getFullPath());
} else {
case_func = false;
}
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case L:
{
printf("ConvertCampaign (.chk): %s, %s", c[u].File, c[u].ArcFile);
Chk chk(storm);
chk.setUnitNames(unitNames);
case_func = chk.convert(c[u].ArcFile, data(c[u].File));
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
default:
break;
}
}
}
UIConsole uic(sub_storm);
// Terran console
string console = "ui/tconsole";
//pixel count from left
int left = 275;
int right = 296;
printf("UIConsole: %s", console.c_str());
uic.convert(graphics(console), left, right);
printf("...%s\n", case_func ? "ok" : "nok");
// Zerg console
console = "ui/zconsole";
left = 274;
right = 281;
printf("UIConsole: %s", console.c_str());
uic.convert(graphics(console), left, right);
printf("...%s\n", case_func ? "ok" : "nok");
// Protoss console
console = "ui/pconsole";
left = 227;
right = 265;
printf("UIConsole: %s", console.c_str());
uic.convert(graphics(console), left, right);
printf("...%s\n", case_func ? "ok" : "nok");
// remove temporary sub files
platform::unlink(sub_storm->getArchiveName());
CreatePanels();
}
else // Casc
{
#ifdef HAVE_CASC_tmp
unsigned int len = sizeof(RMTodo) / sizeof(*RMTodo);
shared_ptr<Casc> hurricane = make_shared<Casc>("/home/andreas/BigSpace/Games/StarCraft");
preferences.setDestDir("data.Stargus.RM");
Control *c = RMTodo;
bool case_func = false;
for (u = 0; u < len; ++u)
{
switch (c[u].Type)
{
case D: // WORKS
{
printf("ConvertDds: %s, %s, %s", mpqfile.c_str(), c[u].File, c[u].ArcFile);
Dds dds(hurricane);
case_func = dds.convert(c[1].ArcFile, c[1].File);
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
case N: // WORKS!
{
printf("ConvertFont: %s, %s, %s", mpqfile.c_str(), c[u].File, c[u].ArcFile);
Font font(hurricane);
case_func = font.convert(c[u].ArcFile, c[u].File);
printf("...%s\n", case_func ? "ok" : "nok");
}
break;
}
}
#endif /* HAVE_CASC */
}
sprintf(buf, "%s/extracted", preferences.getDestDir().c_str());
f = fopen(buf, "w");
fprintf(f, VERSION "\n");
fclose(f);
printf("Done startool!\n");
return 0;
}
| 28,140
|
C++
|
.cpp
| 816
| 28.862745
| 145
| 0.592676
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,107
|
Palette2D.cpp
|
Wargus_stargus/src/Palette2D.cpp
|
/*
* Palette2D.cpp
*
* Author: Andreas Volz
*/
// project
#include "Palette2D.h"
#include "Logger.h"
#include "NoValidPaletteException.h"
// system
#include <fstream>
#include <iostream>
using namespace std;
static Logger logger = Logger("startool.Palette2D");
Palette2D::Palette2D(unsigned int size) :
mColorPalette2D(size)
{
}
Palette2D::Palette2D(std::shared_ptr<DataChunk> rawPalette) :
mColorPalette2D(rawPalette->getSize()/256)
{
/**
* For initial construction just check that the DataChunk is a multiple of 256*3 bytes
* which is an hint for a valid 2D palette.
*/
if((rawPalette->getSize() % (256 * 3)))
{
throw NoValidPaletteException(rawPalette->getSize());
}
load(rawPalette);
}
Palette2D::~Palette2D()
{
}
void Palette2D::load(std::shared_ptr<DataChunk> rawPalette)
{
mColorPalette2D.clear();
unsigned int paletteSize = rawPalette->getSize() / (256*3);
for(unsigned int i = 0; i < paletteSize; i++)
{
shared_ptr<DataChunk> dc = make_shared<DataChunk>();
int start_read_pos = i * 256 *3;
int read_size = 256*3;
dc->addData(rawPalette->getDataPointer() + start_read_pos, read_size);
Palette pal(dc);
mColorPalette2D.push_back(pal);
}
}
std::shared_ptr<DataChunk> Palette2D::createDataChunk()
{
std::shared_ptr<DataChunk> datachunk = make_shared<DataChunk>();
for(Palette &pal : mColorPalette2D)
{
for(unsigned int i = 0; i < 256; i++)
{
unsigned char red = pal.at(i).getRed();
unsigned char green = pal.at(i).getGreen();
unsigned char blue = pal.at(i).getBlue();
datachunk->addData(&red, 1);
datachunk->addData(&green, 1);
datachunk->addData(&blue, 1);
}
}
return datachunk;
}
Color &Palette2D::at(unsigned int column, unsigned int row)
{
auto &color_array = mColorPalette2D.at(row);
Color &color = color_array.at(column);
return color;
}
unsigned int Palette2D::getSize()
{
return mColorPalette2D.size();
}
| 1,980
|
C++
|
.cpp
| 75
| 23.306667
| 88
| 0.698244
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,108
|
Grp.cpp
|
Wargus_stargus/src/Grp.cpp
|
/*
* Grp.cpp
*
* Author: Andreas Volz
*/
// Local
#include <PngExporter.h>
#include "Grp.h"
#include "endian.h"
#include "FileUtil.h"
#include "Storm.h"
#include "Logger.h"
// System
#include <cstdio>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
static Logger logger = Logger("startool.Grp");
Grp::Grp(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane),
mRGBA(false)
{
}
Grp::Grp(std::shared_ptr<Hurricane> hurricane, const std::string &arcfile) :
Converter(hurricane),
mRGBA(false)
{
load(arcfile);
}
Grp::Grp(std::shared_ptr<Hurricane> hurricane, const std::string &arcfile, std::shared_ptr<AbstractPalette> pal) :
Converter(hurricane),
mPal(pal),
mRGBA(false)
{
load(arcfile);
}
Grp::~Grp()
{
}
void Grp::setPalette(std::shared_ptr<AbstractPalette> pal)
{
mPal = pal;
mGRPImage.SetColorPalette(pal);
}
void Grp::setRGBA(bool rgba)
{
mRGBA = rgba;
}
bool Grp::getRGBA()
{
return mRGBA;
}
bool Grp::load(const std::string &arcfile)
{
//mArcfile = arcfile;
std::shared_ptr<DataChunk> dcGrp = mHurricane->extractDataChunk(arcfile);
std::vector<char> GrpVec = dcGrp->getCharVector();
if(dcGrp)
{
mGRPImage.LoadImage(&GrpVec, false);
}
return true;
}
bool Grp::save(Storage filename)
{
bool result = true;
int IPR = 17;
int end_frame = mGRPImage.getNumberOfFrames();
// all IPR < 17 are buildings or similar and stratagus needs them in one image per row
if(end_frame < IPR)
{
IPR = 1;
}
mGRPImage.SaveStitchedPNG(filename.getFullPath(), 0, end_frame, IPR, mRGBA);
return result;
}
Size Grp::getTileSize()
{
Size size (mGRPImage.getMaxImageWidth(), mGRPImage.getMaxImageHeight());
return size;
}
| 1,758
|
C++
|
.cpp
| 83
| 19
| 114
| 0.723198
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,109
|
PngExporter.cpp
|
Wargus_stargus/src/PngExporter.cpp
|
/*
* Png.cpp
*
* Author: Andreas Volz
*/
// Local
#include "FileUtil.h"
#include "PngExporter.h"
#include "Logger.h"
// System
#include <cstring>
#include <stdlib.h>
#include <zlib.h>
#include <iostream>
using namespace std;
static Logger logger = Logger("startool.PngExporter");
PngExporter::PngExporter()
{
}
PngExporter::~PngExporter()
{
}
bool PngExporter::save(const std::string &name, PaletteImage &palImage,
std::shared_ptr<AbstractPalette> abs_palette, int transparent, bool rgba)
{
bool result = false;
std::shared_ptr<Palette> palette = dynamic_pointer_cast<Palette>(abs_palette);
if(palette)
{
if(rgba)
{
result = PngExporter::saveRGBA(name, palImage, *palette, transparent);
}
else
{
result = PngExporter::saveRGB(name, palImage, *palette, transparent);
}
}
else
{
std::shared_ptr<Palette2D> palette2D = dynamic_pointer_cast<Palette2D>(abs_palette);
if(palette2D)
{
result = PngExporter::saveRGBA(name, palImage, *palette2D, transparent);
}
}
return result;
}
bool PngExporter::saveRGB(const std::string &name, PaletteImage &palImage, Palette &palette, int transparent)
{
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
unsigned char **lines;
int i;
std::shared_ptr<DataChunk> palData = palette.createDataChunk();
unsigned char *pal = palData->getDataPointer();
const unsigned char *image = palImage.getRawDataPointer();
CheckPath(name);
if (!(fp = fopen(name.c_str(), "wb")))
{
printf("%s:", name.c_str());
perror("Can't open file");
fflush(stdout);
fflush(stderr);
return false;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
fclose(fp);
return false;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return false;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
free(lines);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return false;
}
png_init_io(png_ptr, fp);
// zlib parameters
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
// prepare the file information
png_set_IHDR(png_ptr, info_ptr, palImage.getSize().getWidth(), palImage.getSize().getHeight(), 8, PNG_COLOR_TYPE_PALETTE,
0, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_invalid(png_ptr, info_ptr, PNG_INFO_PLTE);
png_set_PLTE(png_ptr, info_ptr, (png_colorp) pal, 256);
if (transparent != -1)
{
png_byte trans[256];
memset(trans, 0xFF, sizeof(trans));
trans[transparent] = 0x0;
png_set_tRNS(png_ptr, info_ptr, trans, 256, 0);
}
// write the file header information
png_write_info(png_ptr, info_ptr);
// prepare image
lines = (unsigned char **) malloc(palImage.getSize().getHeight() * sizeof(*lines));
if (!lines)
{
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return false;
}
for (i = 0; i < palImage.getSize().getHeight(); ++i)
{
const unsigned char *line = image + i * palImage.getSize().getWidth();
lines[i] = (unsigned char*) line;
}
png_write_image(png_ptr, lines);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
free(lines);
return true;
}
bool PngExporter::saveRGBA(const std::string &name, PaletteImage &palImage, Palette &palette, int transparent)
{
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
png_bytep *row_pointers = NULL;
const int RGBA_BYTE_SIZE = 4;
CheckPath(name);
if (!(fp = fopen(name.c_str(), "wb")))
{
printf("%s:", name.c_str());
perror("Can't open file");
fflush(stdout);
fflush(stderr);
return false;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
fclose(fp);
return false;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return false;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
free(row_pointers);
row_pointers = NULL;
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return false;
}
png_init_io(png_ptr, fp);
// zlib parameters
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
// prepare the file information
png_set_IHDR(png_ptr, info_ptr, palImage.getSize().getWidth(), palImage.getSize().getHeight(), 8, PNG_COLOR_TYPE_RGBA, 0, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
// write the file header information
png_write_info(png_ptr, info_ptr);
row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * palImage.getSize().getHeight());
for (int h_pos = 0; h_pos < palImage.getSize().getHeight(); ++h_pos)
{
row_pointers[h_pos] = (unsigned char *) malloc(palImage.getSize().getWidth() * RGBA_BYTE_SIZE);
for (int w_pos = 0; w_pos < palImage.getSize().getWidth(); w_pos++)
{
unsigned char pal_pos = palImage.at(Pos(w_pos, h_pos));
Color color;
if (pal_pos != transparent)
{
color = palette.at(pal_pos);
color.setAlpha(255);
}
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 0] = color.getRed();
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 1] = color.getGreen();
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 2] = color.getBlue();
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 3] = color.getAlpha();
}
}
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
if (NULL != row_pointers)
{
for (int h_pos = 0; h_pos < palImage.getSize().getHeight(); ++h_pos)
{
free(row_pointers[h_pos]);
}
free(row_pointers);
row_pointers = NULL;
}
return true;
}
bool PngExporter::saveRGBA(const std::string &name, PaletteImage &palImage, Palette2D &palette2d, int transparent)
{
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
png_bytep *row_pointers = NULL;
const int RGBA_BYTE_SIZE = 4;
bool result = true;
CheckPath(name);
if (!(fp = fopen(name.c_str(), "wb")))
{
printf("%s:", name.c_str());
perror("Can't open file");
fflush(stdout);
fflush(stderr);
return false;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
fclose(fp);
return false;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return false;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
free(row_pointers);
row_pointers = NULL;
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 1;
}
png_init_io(png_ptr, fp);
// zlib parameters
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
// prepare the file information
png_set_IHDR(png_ptr, info_ptr, palImage.getSize().getWidth(), palImage.getSize().getHeight(), 8, PNG_COLOR_TYPE_RGBA, 0, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
// write the file header information
png_write_info(png_ptr, info_ptr);
row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * palImage.getSize().getHeight());
/*
* Count how many lines are allocated in case of Exception cleanup later!
* This is only needed for Palette2D case as this one has dynamic size.
* If you export an GRP with the wrong Palette2D - Bang!
*/
int h_pos_allocated = 0;
try
{
for (int h_pos = 0; h_pos < palImage.getSize().getHeight(); ++h_pos)
{
row_pointers[h_pos] = (unsigned char *) malloc(palImage.getSize().getWidth() * RGBA_BYTE_SIZE);
h_pos_allocated = h_pos;
for (int w_pos = 0; w_pos < palImage.getSize().getWidth(); w_pos++)
{
unsigned char pal_pos = palImage.at(Pos(w_pos, h_pos));
unsigned char pal_beneath = 0;// back palette id #0 (known in the palette format)
Color reference_beneath_color (0, 0, 0); // back palette id #0 (known in the palette format)
Color color_result;
if (pal_pos != transparent)
{
const Color &color_orig = palette2d.at(pal_beneath, pal_pos-1);
color_result = color_orig.blendAgainstReference(reference_beneath_color);
}
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 0] = color_result.getRed();
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 1] = color_result.getGreen();
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 2] = color_result.getBlue();
row_pointers[h_pos][w_pos * RGBA_BYTE_SIZE + 3] = color_result.getAlpha();
}
}
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
}
catch(std::out_of_range &ex)
{
LOG4CXX_ERROR(logger, ex.what());
LOG4CXX_ERROR(logger, "This image couldn't be saved because index out of range error. Very often this happens because wrong palette is used for: " + name);
result = false;
}
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
if (row_pointers != NULL)
{
for (int h_pos = 0; h_pos <= h_pos_allocated; ++h_pos)
{
free(row_pointers[h_pos]);
}
free(row_pointers);
row_pointers = NULL;
}
return result;
}
| 9,374
|
C++
|
.cpp
| 299
| 27.09699
| 179
| 0.657629
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,110
|
platform.cpp
|
Wargus_stargus/src/platform.cpp
|
/*
* platform.cpp
*
* Author: Andreas Volz
*/
#include "platform.h"
#ifdef _MSC_VER
#define DEBUG _DEBUG
#define PATH_MAX _MAX_PATH
#include <direct.h>
#include <io.h>
#define dirname(x) PathRemoveFileSpec(x); if (x[strlen(x) - 1] == '\\') x[strlen(x) - 1] = '\0'
#else
#include <libgen.h>
#include <limits.h>
#include <unistd.h>
#endif
#ifdef _MSC_VER
#include <windows.h>
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <cstring>
namespace platform
{
int unlink(const std::string &pathname)
{
#ifdef _MSC_VER
return ::_unlink(pathname.c_str());
#else
return ::unlink(pathname.c_str());
#endif
}
char *strdup(const char *s)
{
#ifdef WIN32
return ::_strdup(s);
#else
return ::strdup(s);
#endif
}
int mkdir(const std::string &pathname, mode_t mode)
{
#if defined(_MSC_VER) || defined(WIN32)
return ::_mkdir(pathname.c_str());
#else
return ::mkdir(pathname.c_str(), mode);
#endif
}
} /* namespace platform */
| 998
|
C++
|
.cpp
| 53
| 17.320755
| 95
| 0.697002
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,111
|
UnitsConverter.cpp
|
Wargus_stargus/src/UnitsConverter.cpp
|
/*
* UnitsExporter.cpp
*
* Author: Andreas
*/
// project
#include "UnitsConverter.h"
#include "Preferences.h"
#include "FileUtil.h"
#include "Logger.h"
#include "StringUtil.h"
#include "Grp.h"
#include "luagen.h"
#include "dat/DataHub.h"
// system
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <nlohmann/json.hpp>
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.UnitsConverter");
UnitsConverter::UnitsConverter(std::shared_ptr<Hurricane> hurricane, DataHub &datahub) :
Converter(hurricane),
mDatahub(datahub)
{
}
UnitsConverter::~UnitsConverter()
{
}
bool UnitsConverter::convert(json &unitsJson)
{
bool result = true;
Preferences &preferences = Preferences::getInstance();
const int tilesize_pixel = 8; // size of a MiniTile in pixels
const int minitile_multi = 4; // number of MiniTiles in one MegaTile
Storage graphics;
graphics.setDataPath(preferences.getDestDir());
graphics.setDataType("graphics");
Storage luagen;
luagen.setDataPath(preferences.getDestDir());
luagen.setDataType("luagen/units");
CheckPath(luagen.getFullPath());
ofstream lua_include;
lua_include.open (luagen("luagen-units.lua").getFullPath());
string lua_include_str;
/*ofstream lua_sounds;
lua_sounds.open (luagen("luagen-sounds.lua").getFullPath());
string lua_lua_sounds_str;*/
// units.dat
for(auto &array : unitsJson)
{
string unit_name = array.at("name");
int unit_id = array.at("id");
bool extractor = true;
bool save_result = true;
LOG4CXX_TRACE(logger, string("Unit(") + to_string(unit_id) + ")");
try
{
extractor = array.at("extractor");
}
catch (const nlohmann::detail::out_of_range &json_range)
{
extractor = true; // default behaviour TODO: maybe better write into JSON file and skip default
}
if(extractor)
{
Unit unit(mDatahub, unit_id, unit_name);
string grp_arcfile = "unit\\" + unit.flingy_obj().sprite_obj().image_obj().grp_tbl().name1();
// for the LUA reference it's enough to use the idle name as we save only one LUA for idle+talking portrait
string unit_portraits;
try
{
string portrait_name = unit.portrait_obj().video_idle_tbl().name1();
string portrait_id = unit.portrait_obj().getIDString(portrait_name);
string portrait_lua = "portrait_" + portrait_id;
unit_portraits = lg::assign("Portrait", portrait_lua);
}
catch (PropertyNotAvailableException &nex)
{
cout << nex.what() << endl;
// FIXME: just use the tadvisor as some fallback for now
unit_portraits = lg::assign("Portrait", "portrait_tadvisor");
}
Storage lua_file_store(luagen(unit_name + ".lua"));
ofstream lua_file;
lua_file.open (lua_file_store.getFullPath());
// generate sounds Lua -->
string makeLuaReadySounds = makeReadySounds(unit);
string makeLuaWhatSounds = makeWhatSounds(unit);
string makeLuaYesSounds = makeYesSounds(unit);
string makeLuaPissSounds = makePissSounds(unit);
vector<string> unit_LuaSounds;
// add Ready sounds direct to the unit
if(!makeLuaReadySounds.empty())
{
string unit_LuaSound_ready = lg::paramsQuote({"ready", unit_name + "-sound-ready"});
unit_LuaSounds.push_back(unit_LuaSound_ready);
}
// add Yes/Acknowledge sounds direct to the unit
if(!makeLuaYesSounds.empty())
{
string unit_LuaSound_acknowledge = lg::paramsQuote({"acknowledge", unit_name + "-sound-yes"});
unit_LuaSounds.push_back(unit_LuaSound_acknowledge);
}
// make a sound group from What...
vector<string> unit_LuaSelectedSounds;
if(!makeLuaWhatSounds.empty())
{
unit_LuaSelectedSounds.push_back(unit_name + "-sound-what");
}
// ...and Piss group
if(!makeLuaPissSounds.empty())
{
unit_LuaSelectedSounds.push_back(unit_name + "-sound-piss");
}
// create a what/piss sound group if both are existing...
string makeLuaSelectedSound;
// ... and add this sound group to unit Sounds
if(unit_LuaSelectedSounds.size() > 1)
{
string unit_LuaSound_selected = lg::paramsQuote({"selected", unit_name + "-sound-selected"});
unit_LuaSounds.push_back(unit_LuaSound_selected);
makeLuaSelectedSound = lg::function("MakeSoundGroup", {lg::quote(unit_name + "-sound-selected"),
lg::paramsQuote(unit_LuaSelectedSounds)});
}
else if (unit_LuaSelectedSounds.size() == 1) // ...otherwise assign it direct to selected
{
string unit_LuaSound_selected = lg::paramsQuote({"selected", unit_LuaSelectedSounds.at(0)});
unit_LuaSounds.push_back(unit_LuaSound_selected);
}
string unit_sounds = lg::assign("Sounds", lg::table({lg::params(unit_LuaSounds)}));
// generate images and other properties Lua -->
string image_id = unit.flingy_obj().sprite_obj().image_obj().getIDString();
string image_lua = image_id;
string unit_image = lg::assign("Image", image_lua);
string unit_hitpoints = lg::assign("HitPoints", to_string(unit.hitpoints()));
string unit_name_translated = lg::assign("Name", lg::quote(unit.name_tbl().name1()));
bool unit_building = unit.special_ability_flags()->building();
string unit_LuaBuilding = lg::assign("Building", lg::boolean(unit_building));
units_dat_t::unit_dimension_type_t *unit_dimension_tilesize = unit.unit_dimension();
int unit_width = unit_dimension_tilesize->left() + unit_dimension_tilesize->right();
int unit_height = unit_dimension_tilesize->up() + unit_dimension_tilesize->down();
double unit_tilesize_width = unit_width / (double) tilesize_pixel;
double unit_tilesize_height = unit_height / (double) tilesize_pixel;
int unit_boxsize_width = round(unit_tilesize_width * tilesize_pixel);
int unit_boxsize_height = round(unit_tilesize_height * tilesize_pixel);
// for all units which could move (all non-buildings) set a square size as optimization for stratagus
if(!unit_building)
{
unit_tilesize_width = unit_tilesize_height = round(sqrt(unit_tilesize_width * unit_tilesize_height));
}
// ensure minimal unit width
if(unit_tilesize_width < 1)
{
unit_tilesize_width = 1;
}
// ensure minimal unit height
if(unit_tilesize_height < 1)
{
unit_tilesize_height = 1;
}
string unit_LuaTileSize = lg::assign("TileSize", lg::table({lg::integer(unit_tilesize_width), lg::integer(unit_tilesize_height)}));
string unit_LuaBoxSize = lg::assign("BoxSize", lg::table({to_string(unit_boxsize_width), to_string(unit_boxsize_height)}));
// for now just give each unit a PersonalSpace of 1 around
string unit_LuaPersonalSpace = lg::assign("PersonalSpace", lg::table({lg::integer(1), lg::integer(1)}));
int unit_sight_range = unit.sight_range() * minitile_multi;
string unit_computer_reaction_rangeStr ("math.ceil(" + to_string(unit_sight_range) + " * ComputerReactionRangeFactor)");
string unit_person_reaction_rangeStr ("math.floor(" + to_string(unit_sight_range) + " * PersonReactionRangeFactor)");
string unit_LuaSightRange = lg::assign("SightRange", to_string(unit_sight_range));
string unit_LuaComputerReactionRange = lg::assign("ComputerReactionRange", unit_computer_reaction_rangeStr);
string unit_LuaPersonReactionRange = lg::assign("PersonReactionRange", unit_person_reaction_rangeStr);
// generate some standard shadow
Pos shadow_position = Pos(-7, -7);
// some basic flyer shadow support => to be improved
if(unit.elevation_level() >= 16)
{
shadow_position = Pos(15, 15);
}
string unit_shadow = lg::assign("Shadow", lg::table({lg::quote("offset"), lg::posTable(shadow_position), lg::quote("scale"), "1"}));
// generate a dummy animation as fallback to not crash
string unit_animations = lg::assign("Animations", lg::quote("animations-dummy-still"));
// generate a dummy icon as fallback to not crash
string unit_icon = lg::assign("Icon", lg::quote("icon-terran-command-center"));
string unit_LuaNumDirections = lg::assign("NumDirections", image_lua + "_NumDirections");
string unit_LuaType(lg::assign("Type", lg::quote("land"))); // land is fallback
string unit_LuaLandUnit(lg::assign("LandUnit", lg::boolean(true))); // LandUnit=true is fallback
bool unit_flyer = unit.special_ability_flags()->flyer();
string unit_LuaFlyer = lg::assign("AirUnit", lg::boolean(unit_flyer));
if(unit_flyer)
{
unit_LuaType = lg::assign("Type", lg::quote("fly"));
unit_LuaLandUnit = lg::assign("LandUnit", lg::boolean(false));
}
bool unit_organic = unit.special_ability_flags()->organic();
string unit_LuaOrganic = lg::assign("organic", lg::boolean(unit_organic));
int unit_build_time = ((double)unit.build_time() / 24.0) * 6.0; // SC time is 1/24 sec and *6 is stratagus magic
int unit_minaral_costs = unit.mineral_cost();
int unit_vespene_costs = unit.vespene_cost();
string unit_LuaCosts = lg::assign("Costs", lg::table({lg::quote("time"), to_string(unit_build_time),
lg::quote("minerals"), to_string(unit_minaral_costs),
lg::quote("gas"), to_string(unit_vespene_costs)
}));
// FIXME: just make everything able to move as test
//string unit_LuaSpeed = lg::assign("Speed", "10");
string unit_defintion = lg::DefineUnitType(unit_name,
{lg::line(unit_name_translated),
lg::line(unit_image),
lg::line(unit_shadow),
lg::line(unit_icon),
lg::line(unit_animations),
lg::line(unit_portraits),
lg::line(unit_hitpoints),
lg::line(unit_LuaTileSize),
lg::line( unit_LuaBoxSize),
lg::line(unit_LuaSightRange),
lg::line(unit_LuaComputerReactionRange),
lg::line(unit_LuaPersonReactionRange),
lg::line(unit_LuaNumDirections),
lg::line(unit_LuaFlyer),
lg::line(unit_LuaType),
lg::line(unit_LuaBuilding),
lg::line(unit_LuaOrganic),
lg::line(unit_LuaLandUnit),
lg::line(unit_LuaCosts),
lg::line(unit_LuaPersonalSpace),
lg::line(unit_sounds)
});
lua_include_str += lg::line(lg::function("Load", lg::quote(lua_file_store.getRelativePath())));
lua_file << unit_defintion << endl;
// write all the Lua sound functions
if(!makeLuaReadySounds.empty())
{
lua_file << makeLuaReadySounds << endl;
}
if(!makeLuaWhatSounds.empty())
{
lua_file << makeLuaWhatSounds << endl;
}
if(!makeLuaYesSounds.empty())
{
lua_file << makeLuaYesSounds << endl;
}
if(!makeLuaPissSounds.empty())
{
lua_file << makeLuaPissSounds << endl;
}
if(!makeLuaSelectedSound.empty())
{
lua_file << makeLuaSelectedSound << endl;
}
lua_file.close();
}
printf("...%s\n", save_result ? "ok" : "nok");
}
lua_include << lua_include_str;
lua_include.close();
//lua_sounds.close();
return result;
}
std::string UnitsConverter::makeReadySounds(Unit &unit)
{
string make_sound;
try
{
TblEntry unit_ready_sound_tbl_entry = unit.ready_sound_obj().sound_file_tbl();
string unit_sound_ready_id = unit.getIDString() + "-sound-ready";
string unit_ready_sound = unit_ready_sound_tbl_entry.name1();
cout << "Ready Sound: " << unit_ready_sound << endl;
string sound_file_base(unit_ready_sound);
replaceString("\\", "/", sound_file_base);
sound_file_base = cutFileEnding(to_lower(sound_file_base), ".wav");
string sound_file_ogg = "sounds/unit/" + sound_file_base + ".ogg";
make_sound = lg::function("MakeSound", {lg::quote(unit_sound_ready_id), lg::table({lg::quote(sound_file_ogg)})});
}
catch(PropertyNotAvailableException &nex)
{
cout << "no Ready sound: " << nex.what() << endl;
}
return make_sound;
}
std::string UnitsConverter::makeWhatSounds(Unit &unit)
{
string make_sound;
try
{
vector<Sfx> sfx_vec = unit.what_sound_obj();
vector<string> what_sound_vec;
if(!sfx_vec.empty())
{
string unit_sound_ready_id = unit.getIDString() + "-sound-what";
for (auto sfx : sfx_vec)
{
TblEntry unit_what_sound_tbl_entry = sfx.sound_file_tbl();
string unit_what_sound = unit_what_sound_tbl_entry.name1();
cout << "What Sound: " << unit_what_sound << endl;
string sound_file_base(unit_what_sound);
replaceString("\\", "/", sound_file_base);
sound_file_base = cutFileEnding(to_lower(sound_file_base), ".wav");
string sound_file_ogg = "sounds/unit/" + sound_file_base + ".ogg";
what_sound_vec.push_back(sound_file_ogg);
}
string unit_LuaWhatSoundParams = lg::paramsQuote(what_sound_vec);
make_sound = lg::function("MakeSound", {lg::quote(unit_sound_ready_id), lg::table(unit_LuaWhatSoundParams)});
}
}
catch(PropertyNotAvailableException &nex)
{
cout << "no What sound: " << nex.what() << endl;
}
return make_sound;
}
std::string UnitsConverter::makeYesSounds(Unit &unit)
{
string make_sound;
try
{
vector<Sfx> sfx_vec = unit.yes_sound_obj();
vector<string> yes_sound_vec;
if(!sfx_vec.empty())
{
string unit_yes_ready_id = unit.getIDString() + "-sound-yes";
for (auto sfx : sfx_vec)
{
TblEntry unit_yes_sound_tbl_entry = sfx.sound_file_tbl();
string unit_yes_sound = unit_yes_sound_tbl_entry.name1();
cout << "Yes Sound: " << unit_yes_sound << endl;
string sound_file_base(unit_yes_sound);
replaceString("\\", "/", sound_file_base);
sound_file_base = cutFileEnding(to_lower(sound_file_base), ".wav");
string sound_file_ogg = "sounds/unit/" + sound_file_base + ".ogg";
yes_sound_vec.push_back(sound_file_ogg);
}
string unit_LuaYesSoundParams = lg::paramsQuote(yes_sound_vec);
make_sound = lg::function("MakeSound", {lg::quote(unit_yes_ready_id), lg::table(unit_LuaYesSoundParams)});
}
}
catch(PropertyNotAvailableException &nex)
{
cout << "no Yes sound: " << nex.what() << endl;
}
return make_sound;
}
std::string UnitsConverter::makePissSounds(Unit &unit)
{
string make_sound;
try
{
vector<Sfx> sfx_vec = unit.piss_sound_obj();
vector<string> piss_sound_vec;
if(!sfx_vec.empty())
{
string unit_sound_piss_id = unit.getIDString() + "-sound-piss";
for (auto sfx : sfx_vec)
{
TblEntry unit_piss_sound_tbl_entry = sfx.sound_file_tbl();
string unit_piss_sound = unit_piss_sound_tbl_entry.name1();
cout << "Piss Sound: " << unit_piss_sound << endl;
string sound_file_base(unit_piss_sound);
replaceString("\\", "/", sound_file_base);
sound_file_base = cutFileEnding(to_lower(sound_file_base), ".wav");
string sound_file_ogg = "sounds/unit/" + sound_file_base + ".ogg";
piss_sound_vec.push_back(sound_file_ogg);
}
string unit_LuaPissSoundParams = lg::paramsQuote(piss_sound_vec);
make_sound = lg::function("MakeSound", {lg::quote(unit_sound_piss_id), lg::table(unit_LuaPissSoundParams)});
}
}
catch(PropertyNotAvailableException &nex)
{
cout << "no Piss sound: " << nex.what() << endl;
}
return make_sound;
}
std::string UnitsConverter::makeHelpSounds(Unit &unit)
{
return "";
}
} /* namespace dat */
| 16,898
|
C++
|
.cpp
| 381
| 35.322835
| 138
| 0.609976
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,112
|
Dds.cpp
|
Wargus_stargus/src/Dds.cpp
|
/*
* Dds.cpp
*
* Author: Andreas Volz
*/
#ifdef HAVE_IMAGEMAGICKPP
// Local
#include "Dds.h"
#include "Hurricane.h"
#include "FileUtil.h"
#include "Preferences.h"
// System
#include <Magick++.h>
#include <memory>
#include <iostream>
using namespace std;
using namespace Magick;
Dds::Dds(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane)
{
// TODO: might be needed for Windows/OSX regarding docu...
//InitializeMagick(*argv);
}
Dds::~Dds()
{
}
bool Dds::convert(const std::string &arcfile, const std::string &file)
{
bool result = true;
shared_ptr<DataChunk> data = mHurricane->extractDataChunk(arcfile);
if (data)
{
Blob blob(static_cast<void *>(data->getDataPointer()), data->getSize());
// Construct the image object. Seperating image construction from the
// the read operation ensures that a failure to read the image file
// doesn't render the image object useless.
Image image;
try
{
// Read a file into image object
image.read(blob);
Preferences &preferences = Preferences::getInstance();
string targetPath = preferences.getDestDir() + "/" + GRAPHICS_PATH + "/"
+ file;
// Write the image to a file
CheckPath(targetPath);
image.write(targetPath);
}
catch (Exception &error_)
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
}
return result;
}
#endif /* HAVE_IMAGEMAGICKPP */
| 1,477
|
C++
|
.cpp
| 57
| 22.122807
| 78
| 0.668799
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,113
|
Chk.cpp
|
Wargus_stargus/src/Chk.cpp
|
/*
* Chk.cpp
*
* Author: Andreas Volz
*/
// Local
#include <luagen.h>
#include "Chk.h"
#include "WorldMap.h"
#include "endian.h"
#include "Hurricane.h"
#include "FileUtil.h"
#include "Logger.h"
// system
#include <cstring>
#include <cstdint>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#ifdef DEBUG
#define DebugLevel1(x) printf(x)
#define DebugLevel2(x) printf(x)
#define _C_ ,
#else
#define DebugLevel1(x)
#define DebugLevel2(x)
#define _C_
#endif
using namespace std;
static Logger logger = Logger("startool.Chk");
static const char *TypeNames[] =
{
"nobody", NULL, NULL, "rescue-passive", NULL, "computer", "person",
"neutral"
};
static const char *RaceNames[] =
{ "zerg", "terran", "protoss", NULL, "neutral" };
constexpr int MinitileSubdivision = 4;
Chk::Chk(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane),
map(new WorldMap())
{
}
Chk::~Chk()
{
FreeMap();
}
static char *chk_ptr; /// FIXME: docu
static char *chk_endptr; /// FIXME: docu
static int ChkReadHeader(char *header, int32_t *length)
{
int32_t len;
if (chk_ptr >= chk_endptr)
{
return 0;
}
memcpy(header, chk_ptr, 4);
chk_ptr += 4;
memcpy(&len, chk_ptr, 4);
chk_ptr += 4;
*length = ConvertLE32(len);
return 1;
}
/**
** Read dword
*/
static int ChkReadDWord(void)
{
unsigned int temp_int;
memcpy(&temp_int, chk_ptr, 4);
chk_ptr += 4;
return ConvertLE32(temp_int);
}
/**
** Read word
*/
static int ChkReadWord(void)
{
unsigned short temp_short;
memcpy(&temp_short, chk_ptr, 2);
chk_ptr += 2;
return ConvertLE16(temp_short);
}
/**
** Read a byte from #chk_ptr.
**
** @return Next byte from #chk_ptr.
*/
static inline int ChkReadByte(void)
{
int c = *((unsigned char *) chk_ptr);
++chk_ptr;
return c;
}
void Chk::setUnitNames(const std::vector<std::string> &unitNames)
{
mUnitNames = unitNames;
}
void Chk::loadFromBuffer(unsigned char *chkdata, int len)
{
char header[5];
int32_t length;
chk_ptr = (char *) chkdata;
chk_endptr = chk_ptr + len;
header[4] = '\0';
while (ChkReadHeader(header, &length))
{
//
// SCM version
//
if (!memcmp(header, "VER ", 4))
{
if (length == 2)
{
ChkReadWord();
continue;
}
DebugLevel1("Wrong VER length\n");
}
//
// SCM version additional information
//
if (!memcmp(header, "IVER", 4))
{
if (length == 2)
{
ChkReadWord();
continue;
}
DebugLevel1("Wrong IVER length\n");
}
//
// SCM version additional information
//
if (!memcmp(header, "IVE2", 4))
{
if (length == 2)
{
ChkReadWord();
continue;
}
DebugLevel1("Wrong IVE2 length\n");
}
//
// Verification code
//
if (!memcmp(header, "VCOD", 4))
{
if (length == 1040)
{
chk_ptr += 1040;
continue;
}
DebugLevel1("Wrong VCOD length\n");
}
//
// Specifies the owner of the player
//
if (!memcmp(header, "IOWN", 4))
{
if (length == 12)
{
chk_ptr += 12;
continue;
}
DebugLevel1("Wrong IOWN length\n");
}
//
// Specifies the owner of the player, same as IOWN but with 0 added
//
if (!memcmp(header, "OWNR", 4))
{
if (length == 12)
{
for (int i = 0; i < 12; ++i)
{
int p = ChkReadByte();
map->PlayerType[i] = p;
if (p != 0 && p != 3 && p != 5 && p != 6 && p != 7)
{
DebugLevel1("Wrong OWNR type: %d\n" _C_ p);
map->PlayerType[i] = 0;
}
}
continue;
}
DebugLevel1("Wrong OWNR length\n");
}
//
// Terrain type
//
if (!memcmp(header, "ERA ", 4))
{
if (length == 2)
{
int t;
const char *tilesets[] =
{
"badlands", "platform", "install", "ashworld", "jungle", "desert",
"arctic", "twilight"
};
t = ChkReadWord();
map->MapTerrainName = strdup(tilesets[t]);
continue;
}
DebugLevel1("Wrong ERA length\n");
}
//
// Dimensions
//
if (!memcmp(header, "DIM ", 4))
{
if (length == 4)
{
map->MapWidth = ChkReadWord();
map->MapHeight = ChkReadWord();
continue;
}
DebugLevel1("Wrong DIM length\n");
}
//
// Identifies race of each player
//
if (!memcmp(header, "SIDE", 4))
{
if (length == 12)
{
int i;
int v;
for (i = 0; i < 12; ++i)
{
v = ChkReadByte();
if (v == 5)
{
// user selected race
v = 1;
}
if (v > 2 && v != 4 && v != 7)
{
DebugLevel1("Unknown race %d\n" _C_ v);
v = 0;
}
map->PlayerRace[i] = v;
}
continue;
}
DebugLevel1("Wrong SIDE length\n");
}
//
// Graphical tile map
//
if (!memcmp(header, "MTXM", 4))
{
if (length == map->MapWidth * map->MapHeight * 2)
{
map->Tiles = (int *) malloc(
map->MapWidth * map->MapHeight * sizeof(int));
for (int h = 0; h < map->MapHeight; ++h)
{
for (int w = 0; w < map->MapWidth; ++w)
{
int v = ConvertLE16(
((unsigned short *)chk_ptr)[h * map->MapWidth + w]);
/*if (v > 10000) {
v = v;
}*/
map->Tiles[h * map->MapWidth + w] = v;
}
}
chk_ptr += length;
continue;
}
DebugLevel1("Wrong MTXM length\n");
}
//
// Player unit restrictions
//
if (!memcmp(header, "PUNI", 4))
{
if (length == 228 * 12 + 228 + 228 * 12)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong PUNI length\n");
}
//
// Player upgrade restrictions
//
if (!memcmp(header, "UPGR", 4))
{
if (length == 46 * 12 + 46 * 12 + 46 + 46 + 46 * 12)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UPGR length\n");
}
//
// Extended upgrades
//
if (!memcmp(header, "PUPx", 4))
{
if (length == 61 * 12 + 61 * 12 + 61 + 61 + 61 * 12)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong PUPx length\n");
}
//
// Player technology restrictions
//
if (!memcmp(header, "PTEC", 4))
{
if (length == 24 * 12 + 24 * 12 + 24 + 24 + 24 * 12)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong PTEC length\n");
}
//
// Extended player technology restrictions
//
if (!memcmp(header, "PTEx", 4))
{
if (length == 44 * 12 + 44 * 12 + 44 + 44 + 44 * 12)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong PTEx length\n");
}
//
// Units
//
if (!memcmp(header, "UNIT", 4))
{
if (length % 36 == 0)
{
while (length > 0)
{
Unit unit;
chk_ptr += 4; // unknown
unit.X = ChkReadWord(); // x coordinate
unit.Y = ChkReadWord(); // y coordinate
unit.Type = ChkReadWord(); // unit type
chk_ptr += 2; // unknown
unit.Properties = ChkReadWord(); // special properties flag
unit.ValidElements = ChkReadWord(); // valid elements
unit.Player = ChkReadByte(); // owner
unit.HitPointsPercent = ChkReadByte(); // hit point %
unit.ShieldPointsPercent = ChkReadByte(); // shield point %
unit.EnergyPointsPercent = ChkReadByte(); // energy point %
unit.ResourceAmount = ChkReadDWord(); // resource amount
unit.NumUnitsIn = ChkReadWord(); // num units in hanger
unit.StateFlags = ChkReadWord(); // state flags
chk_ptr += 8; // unknown
length -= 36;
if (unit.Player == 11)
{
// neutral player
unit.Player = PlayerMax - 1;
}
unit.X /= 32;
unit.Y /= 32;
// type = UnitTypeByWcNum(t);
// x = (x - 32 * type->TileWidth / 2) / 32;
// y = (y - 32 * type->TileHeight / 2) / 32;
if (unit.Type == SC_StartLocation)
{
map->PlayerStart[unit.Player].X = unit.X;
map->PlayerStart[unit.Player].Y = unit.Y;
}
else
{
map->Units.push_back(unit);
}
}
continue;
}
DebugLevel1("Wrong UNIT length\n");
}
//
// Extended units
//
if (!memcmp(header, "UNIx", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UNIx length\n");
}
//
// Isometric tile mapping
//
if (!memcmp(header, "ISOM", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong ISOM length\n");
}
//
//
//
if (!memcmp(header, "TILE", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong TILE length\n");
}
//
// Doodad map used by the editor
//
if (!memcmp(header, "DD2 ", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong DD2 length\n");
}
//
// Thingys
//
if (!memcmp(header, "THG2", 4))
{
if (length % 10 == 0)
{
while (length > 0)
{
int n;
n = ChkReadWord(); // unit number of the thingy
ChkReadWord(); // x coordinate
ChkReadWord(); // y coordinate
ChkReadByte(); // player number of owner
ChkReadByte(); // unknown
ChkReadWord(); // flags
length -= 10;
string thingyName = mUnitNames[n];
//cout << "Thingy: " << thingyName << endl;
// unit = (char **)hash_find(TheMap.Tileset->ItemsHash, buf);
#ifdef DEBUG
// if (!unit) {
// fprintf(stderr,"THG2 n=%d (%d,%d)\n",n,x,y);
// continue;
// }
#endif
// FIXME: remove
// type = UnitTypeByIdent(*unit);
// x = (x - 32 * type->TileWidth / 2) / 32;
// y = (y - 32 * type->TileHeight / 2) / 32;
// MakeUnitAndPlace(MapOffsetX + x, MapOffsetY + y, type, &Players[15]);
}
continue;
}
DebugLevel1("Wrong THG2 length\n");
}
//
//
//
if (!memcmp(header, "MASK", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong MASK length\n");
}
//
// Strings
//
if (!memcmp(header, "STR ", 4))
{
int i;
unsigned short num;
unsigned short s;
char *cptr = chk_ptr;
num = ChkReadWord();
for (i = 0; i < num; ++i)
{
s = ChkReadWord();
string str(cptr + s);
// replace incompatible line endings of multiline strings
// TODO: this might look ugle, but doesn't crash the LUA function at least
// TODO: need to find a good way when the GUI supports that... maybe remove all multible spaces...
str.erase(remove(str.begin(), str.end(), '\r'), str.end());
str.erase(remove(str.begin(), str.end(), '\n'), str.end());
map->Strings.push_back(str);
}
map->Description = strdup("none");
chk_ptr += length - 2050;
continue;
}
//
//
//
if (!memcmp(header, "UPRP", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UPRP length\n");
}
//
//
//
if (!memcmp(header, "UPUS", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UPUS length\n");
}
//
//
//
if (!memcmp(header, "MRGN", 4))
{
if ((length / 20) * 20 == length)
{
while (length > 0)
{
Location location;
location.StartX = ChkReadDWord();
location.StartY = ChkReadDWord();
location.EndX = ChkReadDWord();
location.EndY = ChkReadDWord();
location.StringNumber = ChkReadWord();
location.Flags = ChkReadWord();
map->Locations.push_back(location);
length -= 20;
}
continue;
}
DebugLevel1("Wrong MRGN length\n");
}
//
// Triggers
//
if (!memcmp(header, "TRIG", 4))
{
if ((length / 2400) * 2400 == length)
{
int i;
while (length > 0)
{
Trigger trigger;
for (i = 0; i < 16; ++i)
{
trigger.TriggerConditions[i].Location = ChkReadDWord();
trigger.TriggerConditions[i].Group = ChkReadDWord();
trigger.TriggerConditions[i].QualifiedNumber = ChkReadDWord();
trigger.TriggerConditions[i].UnitType = ChkReadWord();
trigger.TriggerConditions[i].CompType = ChkReadByte();
trigger.TriggerConditions[i].Condition = ChkReadByte();
trigger.TriggerConditions[i].ResType = ChkReadByte();
trigger.TriggerConditions[i].Flags = ChkReadByte();
chk_ptr += 2;
}
for (i = 0; i < 64; ++i)
{
trigger.TriggerActions[i].Source = ChkReadDWord() - 1;
trigger.TriggerActions[i].TriggerNumber = ChkReadDWord();
trigger.TriggerActions[i].WavNumber = ChkReadDWord();
trigger.TriggerActions[i].Time = ChkReadDWord();
trigger.TriggerActions[i].FirstGroup = ChkReadDWord();
trigger.TriggerActions[i].SecondGroup = ChkReadDWord();
trigger.TriggerActions[i].Status = ChkReadWord();
trigger.TriggerActions[i].Action = ChkReadByte();
trigger.TriggerActions[i].NumUnits = ChkReadByte();
trigger.TriggerActions[i].ActionFlags = ChkReadByte();
chk_ptr += 3;
}
chk_ptr += 32;
map->Triggers.push_back(trigger);
length -= 2400;
}
continue;
}
DebugLevel1("Wrong TRIG length\n");
}
//
// Mission briefing
//
if (!memcmp(header, "MBRF", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong MBRF length\n");
}
//
//
//
if (!memcmp(header, "SPRP", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong SPRP length\n");
}
//
//
//
if (!memcmp(header, "FORC", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong FORC length\n");
}
//
//
//
if (!memcmp(header, "WAV ", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong WAV length\n");
}
//
//
//
if (!memcmp(header, "UNIS", 4))
{
// if (length==) {
if (1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UNIS length\n");
}
//
//
//
if (!memcmp(header, "UPGS", 4))
{
if (length
== 46 * 1 + 46 * 2 + 46 * 2 + 46 * 2 + 46 * 2 + 46 * 2 + 46 * 2)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UPGS length\n");
}
//
//
//
if (!memcmp(header, "UPGx", 4))
{
if (length
== 61 * 1 + 61 * 2 + 61 * 2 + 61 * 2 + 61 * 2 + 61 * 2 + 61 * 2 + 1)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong UPGx length\n");
}
//
//
//
if (!memcmp(header, "TECS", 4))
{
if (length == 24 * 1 + 24 * 2 + 24 * 2 + 24 * 2 + 24 * 2)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong TECS length\n");
}
//
//
//
if (!memcmp(header, "TECx", 4))
{
if (length == 44 * 1 + 44 * 2 + 44 * 2 + 44 * 2 + 44 * 2)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong TECx length\n");
}
//
//
//
if (!memcmp(header, "SWNM", 4))
{
if (length == 256 * 4)
{
chk_ptr += length;
continue;
}
DebugLevel1("Wrong SWNM length\n");
}
DebugLevel2("Unsupported Section: %4.4s\n" _C_ header);
chk_ptr += length;
}
}
/*----------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------*/
#define VERSION "1.0"
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
void Chk::SaveSMP(Storage storage)
{
FILE *fd;
storage.setFilename(storage.getFilename() + "smp");
CheckPath(storage.getFullPath());
fd = fopen(storage.getFullPath().c_str(), "wb");
fprintf(fd, "-- Stratagus Map Presentation\n");
fprintf(fd, "-- File generated automatically from scmconvert V" VERSION "\n");
fprintf(fd, "\n");
fprintf(fd, "DefinePlayerTypes(");
bool first = true;
for (int i = 0; i < PlayerMax; ++i)
{
if (TypeNames[map->PlayerType[i]])
{
if (first)
{
first = false;
}
else
{
fprintf(fd, ",");
}
fprintf(fd, "\"%s\"", TypeNames[map->PlayerType[i]]);
}
}
fprintf(fd, ")\n");
fprintf(fd, "PresentMap(\"%s\", %d, %d, %d, %d)\n", map->Description, 2,
map->MapWidth * MinitileSubdivision, map->MapHeight * MinitileSubdivision, 0);
fclose(fd);
}
void Chk::SaveTrigger(FILE *fd, Trigger *trigger)
{
int i;
TriggerCondition *c;
TriggerAction *a;
// Conditions
for (i = 0; i < 16; ++i)
{
c = &trigger->TriggerConditions[i];
if (c->Condition == 0)
{
break;
}
switch (c->Condition)
{
case 1:
fprintf(fd, "-- CountdownTimer(%d)\n", c->QualifiedNumber);
break;
case 2:
fprintf(fd, "-- Command(%d, %d, %d)\n", c->Group, c->UnitType,
c->QualifiedNumber);
break;
case 3:
fprintf(fd, "-- Bring(%d, %d, [%hu,%hu]-[%hu,%hu], %d)\n", c->Group,
c->UnitType, map->Locations[c->Location].StartX * MinitileSubdivision,
map->Locations[c->Location].StartY * MinitileSubdivision,
map->Locations[c->Location].EndX * MinitileSubdivision, map->Locations[c->Location].EndY * MinitileSubdivision,
c->QualifiedNumber);
break;
case 4:
fprintf(fd, "-- Accumulate(%d, %d, %d)\n", c->Group, c->QualifiedNumber,
c->ResType);
break;
case 5:
fprintf(fd, "-- Kill(%d, %d, %d)\n", c->Group, c->UnitType,
c->QualifiedNumber);
break;
case 6:
fprintf(fd, "-- CommandMost(%d)\n", c->UnitType);
break;
case 7:
fprintf(fd, "-- CommandMostAt(%d, [%hu,%hu]-[%hu,%hu])\n", c->UnitType,
map->Locations[c->Location].StartX * MinitileSubdivision,
map->Locations[c->Location].StartY * MinitileSubdivision,
map->Locations[c->Location].EndX * MinitileSubdivision, map->Locations[c->Location].EndY * MinitileSubdivision);
break;
case 8:
fprintf(fd, "-- MostKills(%d)\n", c->UnitType);
break;
case 9:
fprintf(fd, "-- HighestScore(%d)\n", c->ResType);
break;
case 10:
fprintf(fd, "-- MostResources(%d)\n", c->ResType);
break;
case 11:
fprintf(fd, "-- Switch(%d)\n", c->ResType);
break;
case 12:
fprintf(fd, "-- ElapsedTime(%d)\n", c->QualifiedNumber);
break;
case 13:
fprintf(fd, "-- MissionBriefing()\n");
break;
case 14:
fprintf(fd, "-- Opponents(%d, %d)\n", c->Group, c->QualifiedNumber);
break;
case 15:
fprintf(fd, "-- Deaths(%d, %d, %d)\n", c->Group, c->UnitType,
c->QualifiedNumber);
break;
case 16:
fprintf(fd, "-- CommandLeast(%d)\n", c->UnitType);
break;
case 17:
fprintf(fd, "-- CommandLeastAt(%d, [%hu,%hu]-[%hu,%hu])\n", c->UnitType,
map->Locations[c->Location].StartX * MinitileSubdivision,
map->Locations[c->Location].StartY * MinitileSubdivision,
map->Locations[c->Location].EndX * MinitileSubdivision, map->Locations[c->Location].EndY * MinitileSubdivision);
break;
case 18:
fprintf(fd, "-- LeastKills(%d)\n", c->UnitType);
break;
case 19:
fprintf(fd, "-- LowestScore(%d)\n", c->ResType);
break;
case 20:
fprintf(fd, "-- LeastResources(%d)\n", c->ResType);
break;
case 21:
fprintf(fd, "-- Score(%d, %d, %d)\n", c->Group, c->ResType,
c->QualifiedNumber);
break;
case 22:
fprintf(fd, "-- Always()\n");
break;
case 23:
fprintf(fd, "-- Never()\n");
break;
default:
fprintf(fd, "-- Unhandled condition: %d\n", c->Condition);
break;
}
}
// Actions
for (i = 0; i < 64; ++i)
{
a = &trigger->TriggerActions[i];
if (a->Action == 0)
{
break;
}
switch (a->Action)
{
case 1:
fprintf(fd, "-- ActionVictory()\n");
break;
case 2:
fprintf(fd, "-- ActionDefeat()\n");
break;
case 3:
fprintf(fd, "-- Preserve trigger\n");
break;
case 4:
fprintf(fd, "-- Wait(%d)\n", a->Time);
break;
case 5:
fprintf(fd, "-- Pause\n");
break;
case 6:
fprintf(fd, "-- Unpause\n");
break;
case 7:
fprintf(fd,
"-- Transmission(%s, %d, [%hu,%hu]-[%hu,%hu], %d, %d, %d, %d)\n",
map->Strings[a->TriggerNumber - 1].c_str(), a->Status,
map->Locations[a->Source].StartX * MinitileSubdivision, map->Locations[a->Source].StartY * MinitileSubdivision,
map->Locations[a->Source].EndX * MinitileSubdivision, map->Locations[a->Source].EndY * MinitileSubdivision,
a->Time, a->NumUnits, a->WavNumber, a->Time);
break;
case 8:
fprintf(fd, "-- PlayWav(%d, %d)\n", a->WavNumber, a->Time);
break;
case 9:
fprintf(fd, "-- TextMessage(%s)\n",
map->Strings[a->TriggerNumber - 1].c_str());
break;
case 10:
fprintf(fd, "-- CenterMap(%hu, %hu)\n",
(map->Locations[a->Source].StartX * MinitileSubdivision + map->Locations[a->Source].EndX * MinitileSubdivision)
/ 2 / 32,
(map->Locations[a->Source].StartY * MinitileSubdivision + map->Locations[a->Source].EndY * MinitileSubdivision)
/ 2 / 32);
break;
case 12:
fprintf(fd, "-- SetObjectives(%s)\n",
map->Strings[a->TriggerNumber - 1].c_str());
break;
case 26:
fprintf(fd, "-- SetResources(%d, %d, %d, %d)\n", a->FirstGroup,
a->SecondGroup, a->NumUnits, a->Status);
break;
case 30:
fprintf(fd, "-- Mute unit speech\n");
break;
case 31:
fprintf(fd, "-- Unmute unit speech\n");
break;
default:
fprintf(fd, "-- Unhandled action: %d\n", a->Action);
break;
}
}
}
void Chk::SaveSMS(Storage storage)
{
FILE *fd;
int i;
storage.setFilename(storage.getFilename() + "sms");
CheckPath(storage.getFullPath());
fd = fopen(storage.getFullPath().c_str(), "wb");
fprintf(fd, "-- Stratagus Map Setup\n");
fprintf(fd, "-- File generated automatically from scmconvert V" VERSION "\n");
fprintf(fd, "\n");
for (i = 0; i < PlayerMax; ++i)
{
if (map->PlayerType[i] == 0)
{
// inactive
continue;
}
fprintf(fd, "SetStartView(%d, %d, %d)\n", i, map->PlayerStart[i].X * MinitileSubdivision,
map->PlayerStart[i].Y * MinitileSubdivision);
fprintf(fd, "SetPlayerData(%d, \"Resources\", \"minerals\", %d)\n", i, 0);
fprintf(fd, "SetPlayerData(%d, \"Resources\", \"gas\", %d)\n", i, 0);
fprintf(fd, "SetPlayerData(%d, \"RaceName\", \"%s\")\n", i,
RaceNames[map->PlayerRace[i]]);
}
fprintf(fd, "\n\n");
fprintf(fd, "LoadTileModels(\"luagen/tilesets/%s.lua\")\n",
map->MapTerrainName);
fprintf(fd, "\n\n");
// SetTile(t, x, y);
for (int h = 0; h < map->MapHeight; ++h)
{
for (int w = 0; w < map->MapWidth; ++w)
{
fprintf(fd, "SetTile(%d, %d, %d)\n", map->Tiles[h * map->MapWidth + w], w * MinitileSubdivision,
h * MinitileSubdivision);
}
}
fprintf(fd, "\n\n");
// units
for (i = 0; i < (int) map->Units.size(); ++i)
{
string unitName = mUnitNames[map->Units[i].Type];
string lua_str = lg::line(
lg::assign(
"unit",
lg::CreateUnit(unitName, (map->Units[i]).Player, Pos(map->Units[i].X * MinitileSubdivision, map->Units[i].Y * MinitileSubdivision)))
);
fprintf(fd, "%s", lua_str.c_str()); // TODO: c++ this
if (map->Units[i].ResourceAmount)
{
fprintf(fd, "SetResourcesHeld(unit, %d)\n", map->Units[i].ResourceAmount);
}
}
fprintf(fd, "\n\n");
for (i = 0; i < (int) map->Triggers.size(); ++i)
{
SaveTrigger(fd, (Trigger *) &map->Triggers[i]);
}
fprintf(fd, "\n\n");
/**
* This is some debug code that prints RapidStratagusIDE support as hook into each map
*/
string if_rsi = lg::line(lg::function("if", lg::compare("preferences.RapidStratagusIDE", "true")) + " then");
if_rsi += lg::line(lg::function("Load", lg::quote("RapidStratagusIDE/RSI_Functions.lua")));
if_rsi += lg::line(lg::function("RSI_MapConfiguration"));
if_rsi += lg::line("end");
fprintf(fd, "%s\n", if_rsi.c_str());
/******/
fprintf(fd, "\n\n");
fclose(fd);
}
void Chk::SaveMap(Storage storage)
{
// if a map ends with a dot (.) then it adds .sms and .scp otherwise a dir with scenario.sms/scenario.smp
// TODO: if you give something unexpected to savedir - bye bye => rework later
if (storage.getFullPath().back() == '/')
{
storage.setFilename(storage.getFilename() + "scenario.");
}
SaveSMP(storage);
SaveSMS(storage);
}
void Chk::FreeMap()
{
free(map->Description);
free(map->MapTerrainName);
free(map->Tiles);
delete map;
}
void Chk::ConvertChk(Storage storage, unsigned char *chkdata, int chklen)
{
loadFromBuffer(chkdata, chklen);
SaveMap(storage);
}
bool Chk::convert(const std::string &arcfile, Storage storage)
{
//char buf[1024];
bool result = false;
//Preferences &preferences = Preferences::getInstance();
//sprintf(buf, "%s/%s", preferences.getDestDir().c_str(), file.c_str());
shared_ptr<DataChunk> data = mHurricane->extractDataChunk(arcfile);
if (data)
{
ConvertChk(storage, data->getDataPointer(), data->getSize());
result = true;
}
return result;
}
| 27,357
|
C++
|
.cpp
| 1,055
| 19.51564
| 157
| 0.517115
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,114
|
Smacker.cpp
|
Wargus_stargus/src/Smacker.cpp
|
/*
* Video.cpp
*
* Author: Andreas Volz
*/
// Local
#include <Smacker.h>
#include "Hurricane.h"
#include "FileUtil.h"
#include "platform.h"
#include "Logger.h"
// System
#include <iostream>
using namespace std;
static Logger logger = Logger("startool.Smacker");
Smacker::Smacker(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane)
{
}
Smacker::~Smacker()
{
}
bool Smacker::convertOGV(const std::string &arcfile, Storage storage)
{
bool result = true;
string smk_file = storage.getFullPath() + ".smk";
string ogv_file = storage.getFullPath() + ".ogv";
result = mHurricane->extractFile(arcfile, smk_file, false);
if(result)
{
string ffmpeg_str =
string("ffmpeg -y -i \"") + smk_file
+ "\" -codec:v libtheora -qscale:v 31 -codec:a libvorbis -qscale:a 15 -pix_fmt yuv420p \""
+ ogv_file + "\"";
LOG4CXX_DEBUG(logger, ffmpeg_str);
// TODO: call it in a way we suppress the output to stdout
int sys_call = system(ffmpeg_str.c_str());
if (sys_call != 0)
{
result = false;
}
fs::remove(smk_file);
}
return result;
}
bool Smacker::convertMNG(const std::string &arcfile, Storage storage)
{
bool result = true;
string smk_file = storage.getFullPath() + ".smk";
string png_path = storage.getFullPath() + "_png/";
string mng_file = storage.getFullPath() + ".mng";
result = mHurricane->extractFile(arcfile, smk_file, false);
if(result)
{
CheckPath(png_path);
string ffmpeg_str =
string("ffmpeg -y -i \"") + smk_file + "\" -codec:v png -qscale:v 31 -pix_fmt yuv420p \"" + png_path + "\"image%05d.png";
LOG4CXX_DEBUG(logger, ffmpeg_str);
// TODO: call it in a way we suppress the output to stdout
int sys_call = system(ffmpeg_str.c_str());
if (sys_call == 0)
{
if(result)
{
string mng_cmd = "convert \"" + png_path + "image*.png\" -delay 4 \"" + mng_file + "\"";
LOG4CXX_DEBUG(logger, mng_cmd);
result = callConvert(mng_cmd);
}
}
else
{
result = false;
}
fs::remove(smk_file);
fs::remove_all(png_path);
}
return result;
}
bool Smacker::callConvert(const std::string &cmd)
{
bool result = true;
// try convert with ImageMagick 7+
string magic7_cmd("magick " + cmd);
int sys_call = system(magic7_cmd.c_str());
if (sys_call != 0)
{
// try convert with ImageMagick <= 6
string magic6_cmd(cmd);
sys_call = system(magic6_cmd.c_str());
if (sys_call != 0)
{
// try convert with GraphicsMagick
string gm_cmd("gm " + cmd);
sys_call = system(gm_cmd.c_str());
if (sys_call != 0)
{
result = false;
}
}
}
return result;
}
| 2,722
|
C++
|
.cpp
| 102
| 22.607843
| 127
| 0.625675
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,116
|
StringUtil.cpp
|
Wargus_stargus/src/StringUtil.cpp
|
/*
* stringUtil.cpp
*
* Author: Andreas Volz
*/
#include "StringUtil.h"
#include "Logger.h"
#include <algorithm>
#include <iconv.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
static Logger logger = Logger("startool.StringUtil");
int replaceString(const string &match, const string &replace, string &str)
{
int i = 0;
if (str.find(match) == std::string::npos)
return false;
std::string::size_type start = 0;
while ((start = str.find(match)) != std::string::npos)
{
str.replace(start, match.size(), replace);
i++;
}
return i;
}
bool hasFileEnding(const std::string &filename, const std::string &ending)
{
const size_t loc = filename.find(ending, filename.length() - ending.length());
if (loc != string::npos)
{
return true;
}
return false;
}
std::string cutFileEnding(std::string filename, const std::string &ending)
{
if (ending == "")
{
const size_t loc = filename.find_last_of('.', filename.length());
if (loc != string::npos)
{
filename.erase(loc);
return filename;
}
}
else
{
const size_t loc = filename.find(ending, filename.length() - ending.length());
if (loc != string::npos)
{
filename.erase(loc);
return filename;
}
}
return filename;
}
std::string to_lower(std::string line)
{
std::for_each(line.begin(), line.end(), [](char & c)
{
c = ::tolower(c);
});
return line;
}
// TODO: check if this helps to detect encoding https://github.com/freedesktop/uchardet
char *iconvISO2UTF8(char *iso)
{
char buf[1024] = { '\0' };
iconv_t iconvDesc = iconv_open("UTF-8//TRANSLIT//IGNORE", "ISO-8859-1");
if (iconvDesc == (iconv_t) -1)
{
/* Something went wrong. */
if (errno == EINVAL)
{
snprintf(buf, sizeof(buf), "conversion from '%s' to '%s' not available",
"ISO-8859-1", "UTF-8");
LOG4CXX_ERROR(logger, buf);
}
else
{
snprintf(buf, sizeof(buf), "LibIcon initialization failure");
}
return NULL;
}
size_t iconv_value;
char *utf8 = NULL;
size_t len = 0;
size_t utf8len = 0;
size_t utf8len_save = 0;
char *utf8start = NULL;
len = strlen(iso);
if (!len)
{
snprintf(buf, sizeof(buf), "iconvISO2UTF8: input String is empty.");
LOG4CXX_ERROR(logger, buf);
return NULL;
}
/* Assign enough space to put the UTF-8. */
utf8len = 2 * len;
utf8len_save = utf8len;
utf8 = (char *) calloc(utf8len + 1, sizeof(char));
if (!utf8)
{
snprintf(buf, sizeof(buf), "iconvISO2UTF8: Calloc failed.");
LOG4CXX_ERROR(logger, buf);
return NULL;
}
/* Keep track of the variables. */
utf8start = utf8;
#ifdef _MSC_VER
iconv_value = iconv(iconvDesc, const_cast<const char**>(&iso), &len, &utf8, &utf8len);
#else
iconv_value = iconv(iconvDesc, &iso, &len, &utf8, &utf8len);
#endif
/* Handle failures. */
if (iconv_value == (size_t) -1)
{
switch (errno)
{
/* See "man 3 iconv" for an explanation. */
case EILSEQ:
snprintf(buf, sizeof(buf),
"iconv failed: Invalid multibyte sequence, in string '%s', length %d, out string '%s', length %d\n",
iso, (int) len, utf8start, (int) utf8len);
LOG4CXX_ERROR(logger, buf);
break;
case EINVAL:
snprintf(buf, sizeof(buf),
"iconv failed: Incomplete multibyte sequence, in string '%s', length %d, out string '%s', length %d\n",
iso, (int) len, utf8start, (int) utf8len);
LOG4CXX_ERROR(logger, buf);
break;
case E2BIG:
snprintf(buf, sizeof(buf),
"iconv failed: No more room, in string '%s', length %d, out string '%s', length %d\n",
iso, (int) len, utf8start, (int) utf8len);
LOG4CXX_ERROR(logger, buf);
break;
default:
snprintf(buf, sizeof(buf),
"iconv failed, in string '%s', length %d, out string '%s', length %d\n",
iso, (int) len, utf8start, (int) utf8len);
LOG4CXX_ERROR(logger, buf);
}
return NULL;
}
if (iconv_close(iconvDesc) != 0)
{
snprintf(buf, sizeof(buf), "libicon close failed: %s", strerror(errno));
LOG4CXX_ERROR(logger, buf);
}
utf8start[utf8len_save] ='\0';
return utf8start;
}
| 4,270
|
C++
|
.cpp
| 155
| 23.012903
| 118
| 0.618022
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,117
|
DataChunk.cpp
|
Wargus_stargus/src/DataChunk.cpp
|
/*
* DataChunk.cpp
*
* Author: Andreas Volz
*/
// Local
#include "DataChunk.h"
#include "Logger.h"
// System
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
using namespace std;
static Logger logger = Logger("startool.DataChunk");
DataChunk::DataChunk() :
mData(nullptr), mSize(0)
{
}
DataChunk::DataChunk(const DataChunk &datachunk) :
mData(nullptr), mSize(0)
{
addData(datachunk.mData, datachunk.mSize);
}
DataChunk::DataChunk(unsigned char **data, const size_t size)
{
mData = *data;
mSize = size;
}
DataChunk::~DataChunk()
{
free(mData);
mData = nullptr;
}
void DataChunk::addData(unsigned char *data, const size_t size)
{
mData = (unsigned char *) realloc(mData, mSize * sizeof(unsigned char) + size * sizeof(unsigned char));
memcpy(mData + mSize * sizeof(unsigned char), data, size);
mSize += size;
}
void DataChunk::replaceData(unsigned char *data, const size_t size, size_t pos)
{
size_t new_size = pos * sizeof(unsigned char) + size * sizeof(unsigned char);
if (new_size > mSize)
{
mData = (unsigned char *) realloc(mData, new_size);
mSize = new_size;
}
memcpy(mData + pos * sizeof(unsigned char), data, size);
}
unsigned char *DataChunk::getDataPointer() const
{
return mData;
}
size_t DataChunk::getSize() const
{
return mSize;
}
std::vector<unsigned char> DataChunk::getUCharVector() const
{
return std::vector<unsigned char>(mData, mData + mSize);
}
std::vector<char> DataChunk::getCharVector() const
{
return std::vector<char>(mData, mData + mSize);
}
bool DataChunk::write(const std::string &filename)
{
bool result = true;
ofstream wf(filename, ios::out | ios::binary);
if (wf)
{
for (size_t i = 0; i < mSize; i++)
{
wf.write((char *) &mData[i], sizeof(unsigned char));
}
wf.close();
}
else
{
LOG4CXX_ERROR(logger, string("Couldn't write in: ") + filename);
result = false;
}
return result;
}
bool DataChunk::read(const std::string &filename)
{
streampos size;
char *memblock;
bool result = false;
ifstream file(filename, ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read(memblock, size);
if(file)
{
addData(reinterpret_cast<unsigned char*>(memblock), size);
result = true;
}
else
{
LOG4CXX_ERROR(logger, string("Couldn't read from: ") + filename);
}
file.close();
delete[] memblock;
}
return result;
}
unsigned char DataChunk::at(size_t pos)
{
unsigned char ret = '\0';
if (pos < mSize)
{
ret = mData[pos];
}
else
{
LOG4CXX_WARN(logger, "'pos' bigger then data: " + to_string(pos) + " < " + to_string(mSize));
}
return ret;
}
| 2,799
|
C++
|
.cpp
| 124
| 19.701613
| 105
| 0.671326
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,119
|
Breeze.cpp
|
Wargus_stargus/src/Breeze.cpp
|
/*
* Breeze.cpp
*
* Author: Andreas Volz
*/
// Local
#include "Breeze.h"
#include "FileUtil.h"
#include "Logger.h"
#include "StringUtil.h"
// System
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <zlib.h>
#include <optional>
using namespace std;
static Logger logger = Logger("startool.Breeze");
Breeze::Breeze()
{
}
Breeze::~Breeze()
{
closeArchive();
}
Breeze::Breeze(const std::string &archiveName)
{
openArchive(archiveName);
}
bool Breeze::openArchive(const std::string &archiveName)
{
mArchiveName = archiveName;
return true;
}
void Breeze::closeArchive()
{
mArchiveName.clear();
}
bool Breeze::extractFile(const std::string &archivedFile, const std::string &extractedName, bool compress)
{
unsigned char *szEntryBuffer = nullptr;
size_t bufferLen = 0;
bool result = false;
FILE *file = nullptr; // Disk file handle
gzFile gzfile = nullptr; // Compressed file handle
if (extractMemory(archivedFile, &szEntryBuffer, &bufferLen))
{
CheckPath(extractedName);
if (compress)
{
gzfile = gzopen(extractedName.c_str(), "wb9");
if (gzfile)
{
int bytes_written = gzwrite(gzfile, szEntryBuffer, bufferLen);
gzclose(gzfile);
if (bytes_written != (int) bufferLen)
{
LOG4CXX_FATAL(logger, "Wrong buffer len:" + to_string(bytes_written) + "!=" + to_string(bufferLen));
}
}
}
else
{
file = fopen(extractedName.c_str(), "wb");
if (file)
{
size_t dwBytes = fwrite(szEntryBuffer, sizeof(char), bufferLen, file);
fclose(file);
if (dwBytes != bufferLen)
{
LOG4CXX_FATAL(logger, "Wrong buffer len:" + to_string(dwBytes) + "!=" + to_string(bufferLen));
}
}
}
free(szEntryBuffer);
result = true;
}
return result;
}
bool Breeze::extractMemory(const std::string &archivedFile, unsigned char **szEntryBufferPrt, size_t *bufferLen)
{
FILE *f;
bool result = true;
unsigned char *szEntryBuffer = nullptr;
string archivedFilePath = mArchiveName + "/" + archivedFile;
replaceString("\\", "/", archivedFilePath);
f = fopen(archivedFilePath.c_str(), "r");
if (f)
{
unsigned char szBuffer[0x10000];
size_t len = 0;
int i = 0;
size_t dwBytes = 1;
while (dwBytes > 0)
{
dwBytes = fread(szBuffer, sizeof(char), sizeof(szBuffer), f);
if (dwBytes > 0)
{
len = len + dwBytes;
szEntryBuffer = (unsigned char *) realloc(szEntryBuffer, len);
memcpy(szEntryBuffer + (i * sizeof(szBuffer)), szBuffer, dwBytes);
}
}
i++;
*bufferLen = len;
}
else
{
result = false;
}
*szEntryBufferPrt = szEntryBuffer;
return result;
}
std::shared_ptr<std::istream> Breeze::extractStream(const std::string &archivedFile)
{
string archivedFilePath = mArchiveName + "/" + archivedFile;
replaceString("\\", "/", archivedFilePath);
auto stream = std::make_shared<std::ifstream>(archivedFilePath);
return std::shared_ptr<std::ifstream>(*stream ? std::move(stream) : nullptr);
}
| 3,124
|
C++
|
.cpp
| 120
| 21.983333
| 112
| 0.65413
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,120
|
Color.cpp
|
Wargus_stargus/src/Color.cpp
|
/*
* Color.cpp
*
* Author: Andreas Volz
*/
// project
#include <Color.h>
// system
#include <algorithm>
Color::Color() :
mRed(0),
mGreen(0),
mBlue(0),
mAlpha(0)
{
}
Color::Color(const Color &color) :
mRed(color.mRed),
mGreen(color.mGreen),
mBlue(color.mBlue),
mAlpha(0)
{
}
Color::Color(unsigned char red, unsigned char green, unsigned char blue) :
mRed(red),
mGreen(green),
mBlue(blue),
mAlpha(0)
{
}
Color::Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) :
mRed(red),
mGreen(green),
mBlue(blue),
mAlpha(alpha)
{
}
Color::~Color()
{
}
void Color::setRed(unsigned char color)
{
mRed = color;
}
void Color::setGreen(unsigned char color)
{
mGreen = color;
}
void Color::setBlue(unsigned char color)
{
mBlue = color;
}
void Color::setAlpha(unsigned char color)
{
mAlpha = color;
}
unsigned char Color::getRed() const
{
return mRed;
}
unsigned char Color::getGreen() const
{
return mGreen;
}
unsigned char Color::getBlue() const
{
return mBlue;
}
unsigned char Color::getAlpha() const
{
return mAlpha;
}
unsigned char Color::getBiggestColor() const
{
return std::max(std::max(mRed, mGreen), mBlue);
}
Color Color::getBrighened() const
{
double color_factor = getBiggestColor() / 255.0;
unsigned char bright_red = mRed / color_factor;
unsigned char bright_green = mGreen / color_factor;
unsigned char bright_blue = mBlue / color_factor;
Color bright_color(bright_red, bright_green, bright_blue);
return bright_color;
}
Color Color::blendAgainstReference(const Color &reference) const
{
Color color_bright = getBrighened();
double alpha = 0;
// red biggest
if((getRed() > getGreen()) &
(getRed() > getBlue()))
{
alpha = (double) (getRed() - reference.getRed()) /
(double) (color_bright.getRed() - reference.getRed());
}
// green is biggest
else if((getGreen() > getRed()) &
(getGreen() > getBlue()))
{
alpha = (double) (getGreen() - reference.getGreen()) /
(double) (color_bright.getGreen() - reference.getGreen());
}
// blue is biggest
{
alpha = (double) (getBlue() - reference.getBlue()) /
(double) (color_bright.getBlue() - reference.getBlue());
}
unsigned char red = alpha * getRed() + (1 - alpha) * reference.getRed();
unsigned char green = alpha * getGreen() + (1 - alpha) * reference.getGreen();
unsigned char blue = alpha * getBlue() + (1 - alpha) * reference.getBlue();
Color color_result (red, green, blue, alpha * 255);
return color_result;
}
Color& Color::operator=(const Color& color)
{
mRed = color.mRed;
mGreen = color.mGreen;
mBlue = color.mBlue;
mAlpha = color.mAlpha;
return *this;
}
| 2,753
|
C++
|
.cpp
| 122
| 19.819672
| 95
| 0.680802
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,121
|
Preferences.cpp
|
Wargus_stargus/src/Preferences.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/* STD */
#include <iostream>
#include "Preferences.h"
using namespace std;
Preferences &Preferences::getInstance()
{
static Preferences instance;
return instance;
}
void Preferences::init()
{
mVideoExtraction = false;
mDestDir = "data";
}
void Preferences::setVideoExtraction(bool video)
{
mVideoExtraction = video;
}
bool Preferences::getVideoExtraction()
{
return mVideoExtraction;
}
void Preferences::setSoundExtraction(bool sound)
{
mSoundExtraction = sound;
}
bool Preferences::getSoundExtraction()
{
return mSoundExtraction;
}
void Preferences::setArchiveDir(const std::string &dir)
{
mArchiveDir = dir;
}
const std::string Preferences::getArchiveDir()
{
return mArchiveDir;
}
void Preferences::setDestDir(const std::string &dir)
{
mDestDir = dir;
}
const std::string Preferences::getDestDir()
{
return mDestDir;
}
| 907
|
C++
|
.cpp
| 49
| 16.755102
| 55
| 0.786982
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,122
|
Storage.cpp
|
Wargus_stargus/src/Storage.cpp
|
/*
* Storage.cpp
*
* Author: Andreas Volz
*/
// project
#include "Storage.h"
// system
#include <iostream>
using namespace std;
Storage::Storage()
{
}
Storage::Storage(const char *filename) :
mFilename(filename)
{
}
Storage::Storage(const std::string &filename) :
mFilename(filename)
{
}
Storage::~Storage()
{
}
const std::string& Storage::getDataPath() const
{
return mDataPath;
}
void Storage::setDataPath(const std::string &dataPath)
{
this->mDataPath = dataPath;
}
const std::string &Storage::getDataType() const
{
return mDataType;
}
void Storage::setDataType(const std::string &dataType)
{
this->mDataType = dataType;
}
const std::string &Storage::getFilename() const
{
return mFilename;
}
void Storage::setFilename(const std::string &filename)
{
this->mFilename = filename;
}
std::string Storage::getFullPath() const
{
string path = getDataPath();
if(!path.empty())
{
path += "/";
}
path += getDataType();
if(!path.empty())
{
path += "/";
}
path += getFilename();
return path;
}
std::string Storage::getRelativePath() const
{
string path = getDataType();
if(!path.empty())
{
path += "/";
}
path += getFilename();
return path;
}
Storage Storage::operator()(std::string filename)
{
Storage storage(*this);
storage.setFilename(filename);
return storage;
}
std::string Storage::operator=(const Storage& storage)
{
return getFullPath();
}
Storage::operator std::string() const
{
return getFullPath();
}
std::string operator+(const std::string &str, const Storage& storage)
{
return str + storage.getFullPath();
}
std::string operator+(const Storage& storage, const std::string &str)
{
return storage.getFullPath() + str;
}
std::string operator+(const char *str, const Storage& storage)
{
return str + storage.getFullPath();
}
std::string operator+(const Storage& storage, const char *str)
{
return storage.getFullPath() + str;
}
| 1,955
|
C++
|
.cpp
| 103
| 16.825243
| 69
| 0.715702
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,123
|
Wav.cpp
|
Wargus_stargus/src/Wav.cpp
|
/*
* Wav.cpp
*
* Author: Andreas Volz
*/
// project
#include "Wav.h"
#include "Hurricane.h"
#include "platform.h"
#include "Logger.h"
#include "FileUtil.h"
// system
using namespace std;
static Logger logger = Logger("startool.Wav");
Wav::Wav(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane)
{
}
Wav::Wav(std::shared_ptr<Hurricane> hurricane, const std::string &arcfile) :
Converter(hurricane)
{
}
Wav::~Wav()
{
}
bool Wav::convert(const std::string &arcfile, Storage storage)
{
bool result = true;
string wav_file = storage.getFullPath() + ".wav";
string ogg_file = storage.getFullPath() + ".ogg";
CheckPath(wav_file);
result = mHurricane->extractFile(arcfile, wav_file, false);
string ffmpeg_str =
string("ffmpeg -y -i \"") + wav_file
+ "\" -acodec libvorbis \""
+ ogg_file + "\"";
//cout << "video: " << ffmpeg_str << endl;
// TODO: call it in a way we suppress the output to stdout
int sys_call = system(ffmpeg_str.c_str());
if (sys_call != 0)
{
result = false;
}
fs::remove(wav_file);
return result;
}
| 1,095
|
C++
|
.cpp
| 46
| 21.304348
| 76
| 0.668605
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,124
|
SfxConverter.cpp
|
Wargus_stargus/src/SfxConverter.cpp
|
/*
* SfxConverter.cpp
*
* Author: Andreas Volz
*/
// project
#include "SfxConverter.h"
#include "Storage.h"
#include "Preferences.h"
#include "FileUtil.h"
#include "dat/Sfx.h"
#include "Wav.h"
#include "Logger.h"
#include "StringUtil.h"
// system
#include <iostream>
#include <fstream>
using namespace std;
using namespace dat;
static Logger logger = Logger("startool.dat.SfxConverter");
SfxConverter::SfxConverter(std::shared_ptr<Hurricane> hurricane, DataHub &datahub) :
Converter(hurricane),
mDatahub(datahub)
{
}
SfxConverter::~SfxConverter()
{
}
bool SfxConverter::convert()
{
bool result = true;
Preferences &preferences = Preferences::getInstance();
Storage sounds;
sounds.setDataPath(preferences.getDestDir());
sounds.setDataType("sounds/unit");
// start with i=1 as 0=none and couldn't be read
for(unsigned int i = 1; i < static_cast<unsigned int>(mDatahub.sfxdata->num_lines()); i++)
{
Sfx sfx(mDatahub, i);
string sound_id;
/*Storage lua_file_store(luagen("sound-" + sound_id + ".lua"));
ofstream lua_file;
lua_file.open (lua_file_store.getFullPath());*/
TblEntry sound_file = sfx.sound_file_tbl();
string sound_arcfile("sound\\" + sound_file.name1());
string sound_file_base(sound_file.name1());
replaceString("\\", "/", sound_file_base);
sound_file_base = cutFileEnding(to_lower(sound_file_base), ".wav");
LOG4CXX_TRACE(logger, "sound_arcfile: " + sound_arcfile);
LOG4CXX_TRACE(logger, "sound_file_base: " + sound_file_base);
Wav wav(mHurricane);
bool case_func = wav.convert(sound_arcfile, sounds(sound_file_base));
printf("...%s\n", case_func ? "ok" : "nok");
}
return result;
}
| 1,709
|
C++
|
.cpp
| 56
| 27.553571
| 92
| 0.70141
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,125
|
ImagesConverter.cpp
|
Wargus_stargus/src/ImagesConverter.cpp
|
/*
* ImagesConverter.cpp
*
* Author: Andreas Volz
*/
// project
#include "ImagesConverter.h"
#include "Logger.h"
#include "Preferences.h"
#include "Storage.h"
#include "luagen.h"
#include "FileUtil.h"
#include "dat/Image.h"
#include "StringUtil.h"
#include "Grp.h"
// system
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using namespace dat;
static Logger logger = Logger("startool.dat.ImagesConverter");
ImagesConverter::ImagesConverter(std::shared_ptr<Hurricane> hurricane, DataHub &datahub) :
Converter(hurricane),
mDatahub(datahub)
{
}
ImagesConverter::~ImagesConverter()
{
}
bool ImagesConverter::convert(std::map<std::string, std::shared_ptr<AbstractPalette>> &paletteMap)
{
bool result = true;
Preferences &preferences = Preferences::getInstance();
Storage graphics;
graphics.setDataPath(preferences.getDestDir());
graphics.setDataType("graphics");
Storage luagen;
luagen.setDataPath(preferences.getDestDir());
luagen.setDataType("luagen/images");
CheckPath(luagen.getFullPath());
ofstream lua_include;
lua_include.open (luagen("luagen-images.lua").getFullPath());
string lua_include_str;
for (unsigned int i = 0; i < mDatahub.images->grp()->size(); i++)
{
Image image(mDatahub, i);
string grp_name(image.grp_tbl().name1());
grp_name = to_lower(grp_name); // make lower case to match it always
LOG4CXX_TRACE(logger, "image: " + grp_name);
/* The following code splits a full GRP path/file into a logic of image type, subtype and subsubtype.
* The idea is to identify the logic which palette should be used to decode that specific GRP image.
*/
string imageType;
string imageSubType;
string imageSubSubType;
// find first slash
size_t found = grp_name.find('\\');
if(found != string::npos)
{
imageType = grp_name.substr (0, found);
LOG4CXX_TRACE(logger, "imageType: " + imageType);
// find second slash
size_t found2 = grp_name.find('\\', found+1);
if(found2 != string::npos)
{
imageSubType = grp_name.substr (found+1, found2 - found-1);
LOG4CXX_TRACE(logger, "imageSubType: " + imageSubType);
// find third slash
size_t found3 = grp_name.find('\\', found2+1);
if(found3 != string::npos)
{
imageSubSubType = grp_name.substr (found2+1, found3 - found2-1);
LOG4CXX_TRACE(logger, "imageSubSubType: " + imageSubSubType);
}
}
}
string grp_arcfile = "unit\\" + grp_name;
Grp grp(mHurricane, grp_arcfile);
std::shared_ptr<AbstractPalette> pal;
string remapping;
bool save_grp = true;
if (image.draw_function() == images_dat_t::DRAW_FUNCTION_ENUM_REMAPPING)
{
if(image.remapping() == images_dat_t::REMAPPING_ENUM_OFIRE)
{
remapping = "ofire";
}
else if(image.remapping() == images_dat_t::REMAPPING_ENUM_GFIRE)
{
remapping = "gfire";
}
else if(image.remapping() == images_dat_t::REMAPPING_ENUM_BFIRE)
{
remapping = "bfire";
}
else if(image.remapping() == images_dat_t::REMAPPING_ENUM_BEXPL)
{
remapping = "bexpl";
}
else // as default use ofire until I've a better idea....
{
remapping = "ofire";
}
pal = paletteMap.at(remapping);
grp.setPalette(pal);
grp.setRGBA(true);
}
else if (image.draw_function() == images_dat_t::DRAW_FUNCTION_ENUM_SHADOW)
{
// do not export shadows images as the stratagus engine has a better way to generate them
save_grp = false;
}
else // all other drawing functions until I identify a special case
{
string tileset;
if(imageType == "thingy" && imageSubType == "tileset" && !imageSubSubType.empty())
{
tileset = imageSubSubType;
pal = paletteMap.at(tileset);
}
else // in all other cases use the "tunit" palette
{
pal = paletteMap.at("tunit");
}
}
// FIXME: some blacklisting until I know why it crash!
if(grp_name == "thingy\\blackx.grp")
{
save_grp = false;
}
// FIXME: some hard coded defaults to assign other palettes
// make this configurable or find out if this is in the data
else if(grp_name == "terran\\tank.grp")
{
// TODO: player color isn't available. But no problem visible for now.
// maybe need to add cunit palette before into tileset palette?
pal = paletteMap.at("badlands");
}
else if(grp_name == "neutral\\cbattle.grp")
{
// TODO: player color isn't available. See how to fix this (or if this is needed for neutral)
pal = paletteMap.at("badlands");
}
else if(grp_name == "neutral\\ion.grp")
{
pal = paletteMap.at("platform");
}
else if(grp_name == "neutral\\khyad01.grp")
{
pal = paletteMap.at("jungle");
}
else if(grp_name == "neutral\\temple.grp")
{
pal = paletteMap.at("jungle");
}
else if(grp_name == "neutral\\geyser.grp")
{
/* FIXME: only the first frame is correct, but this looks ok as we use only this one in animation
frame 0 = "badlands.wpe" (default frame for all other tilesets)
frame 1 = "platform.wpe"
frame 2 = "install.wpe"
frame 3 = "ashworld.wpe"
*/
pal = paletteMap.at("badlands");
}
grp.setPalette(pal);
if(save_grp)
{
string grp_storage_file(grp_arcfile);
replaceString("\\", "/", grp_storage_file);
// cut the file ending and lower case it
string grp_storage_file_base = to_lower(cutFileEnding(grp_storage_file, ".grp"));
// if a remapping function is used for that Grp than save with specific name
if(!remapping.empty())
{
grp_storage_file_base += "_" + remapping;
}
Storage png_file = graphics(grp_storage_file_base + ".png");
result = grp.save(png_file);
string image_id = image.getIDString();
string image_lua = image_id + ".lua";
Storage lua_file_store(luagen(image_lua));
// only generate LUA file with the image properties in case it could be saved successful
if(result)
{
ofstream lua_file;
lua_file.open (lua_file_store.getFullPath());
Size tilesize = grp.getTileSize();
int NumDirections = 1;
if(image.gfx_turns() == true)
{
// it seems all animations which are calculated by gfx_turns have 32 directions
NumDirections = 32;
}
string unit_image_file(lg::assign(image_id + "_file", lg::quote(png_file.getRelativePath())));
lua_file << unit_image_file << endl;
string unit_image_size(lg::assign(image_id + "_size", lg::sizeTable(tilesize)));
lua_file << unit_image_size << endl;
string unit_image_NumDirections(lg::assign(image_id + "_NumDirections", to_string(NumDirections)));
lua_file << unit_image_NumDirections << endl;
string unit_image_table(
lg::table({lg::quote("file"), image_id + "_file",
lg::quote("size") , image_id + "_size"}));
string unit_image = lg::assign(image_id, unit_image_table);
lua_file << unit_image << endl;
string unit_image_table_var(
lg::table({lg::assign("File", image_id + "_file"),
lg::assign("Size" , image_id + "_size")}));
string unit_image_var = lg::assign(image_id + "_var", unit_image_table_var);
lua_file << unit_image_var << endl;
lua_file.close();
string grp_save_trace(to_string(i) + ": " + grp_name + " : " + grp_arcfile + " => " + grp_storage_file_base);
LOG4CXX_TRACE(logger, grp_save_trace);
}
// write the Load call even if Grp not present to preserve the SC base files
lua_include_str += lg::line(lg::function("Load", lg::quote(lua_file_store.getRelativePath())));
}
}
lua_include << lua_include_str;
lua_include.close();
return result;
}
| 8,037
|
C++
|
.cpp
| 223
| 29.955157
| 118
| 0.631504
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,126
|
PortraitsConverter.cpp
|
Wargus_stargus/src/PortraitsConverter.cpp
|
/*
* PortraitsConverter.cpp
*
* Author: Andreas Volz
*/
// project
#include "PortraitsConverter.h"
#include "dat/Portrait.h"
#include "Smacker.h"
#include "StringUtil.h"
#include "Preferences.h"
#include "FileUtil.h"
#include "platform.h"
#include "luagen.h"
#include "Logger.h"
// system
#include <iostream>
#include <fstream>
#include <set>
using namespace std;
using namespace dat;
static Logger mLogger = Logger("startool.dat.PortraitsConverter");
PortraitsConverter::PortraitsConverter(std::shared_ptr<Hurricane> hurricane, DataHub &datahub) :
Converter(hurricane),
mDatahub(datahub)
{
}
PortraitsConverter::~PortraitsConverter()
{
}
bool PortraitsConverter::convert()
{
bool result = true;
Preferences &preferences = Preferences::getInstance();
Storage videos;
videos.setDataPath(preferences.getDestDir());
videos.setDataType("videos/portrait");
Storage luagen;
luagen.setDataPath(preferences.getDestDir());
luagen.setDataType("luagen/portrait");
CheckPath(luagen.getFullPath());
ofstream lua_include;
lua_include.open (luagen("luagen-portrait.lua").getFullPath());
string lua_include_str;
for(unsigned int i = 0; i < mDatahub.portdata->video_idle()->size(); i++)
{
Portrait portrait(mDatahub, i);
string portrait_arcfile_idle(portrait.video_idle_tbl().name1());
string portrait_arcfile_talking(portrait.video_talking_tbl().name1());
string portrait_idle_id(portrait.getIDString(portrait_arcfile_idle));
string portrait_talking_id(portrait.getIDString(portrait_arcfile_talking));
// just to ensure the idle / talking consistency in the database
// this should also be the case otherwise something is broken
if(portrait_idle_id == portrait_talking_id)
{
Storage lua_file_store(luagen("portrait-" + portrait_idle_id + ".lua"));
ofstream lua_file;
lua_file.open (lua_file_store.getFullPath());
vector<string> portrait_list;
convertMngPortraits(portrait_arcfile_idle, portrait_list);
portrait_list.push_back("talking"); // the stratagus API needs this as separator
convertMngPortraits(portrait_arcfile_talking, portrait_list);
string portraits_table = lg::assign("portrait_" + portrait_idle_id ,lg::table(lg::paramsQuote(portrait_list)));
lua_include_str += lg::line(lg::function("Load", lg::quote(lua_file_store.getRelativePath())));
lua_file << portraits_table;
lua_file.close();
}
else
{
LOG4CXX_FATAL(mLogger, "portrait_idle_id != portrait_talking_id");
}
}
lua_include << lua_include_str;
lua_include.close();
return result;
}
bool PortraitsConverter::convertMngPortraits(const std::string &arcfile, std::vector<std::string> &portrait_list)
{
bool smk_available = true;
unsigned int smk_num = 0;
Preferences &preferences = Preferences::getInstance();
Storage videos;
videos.setDataPath(preferences.getDestDir());
videos.setDataType("videos/portrait");
while(smk_available && smk_num <= 3)
{
Smacker video(mHurricane);
// build the name of the specific #smk file
string smk_arcfile("portrait\\" + arcfile + to_string(smk_num) + ".smk");
// target place where to store the file
string target_basename(arcfile + to_string(smk_num));
replaceString("\\", "/", target_basename);
target_basename = to_lower(target_basename);
cout << "Try export (last one may fail if less then three) " << smk_arcfile << " to " << target_basename;
smk_available = video.convertMNG(smk_arcfile, videos(target_basename));
if(smk_available)
{
portrait_list.push_back(videos.getDataType() + "/" + target_basename + ".mng");
}
printf("...%s\n", smk_available ? "ok" : "nok");
smk_num++;
}
return true;
}
| 3,777
|
C++
|
.cpp
| 104
| 32.528846
| 117
| 0.71515
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,127
|
Panel.cpp
|
Wargus_stargus/src/Panel.cpp
|
/*
* Panel.cpp
*
* Author: Andreas Volz
*/
// Local
#include "Panel.h"
#include "FileUtil.h"
#include "Preferences.h"
// System
#include <png.h>
#include <zlib.h>
Panel::Panel()
{
}
Panel::~Panel()
{
}
/**
* TODO: get an understanding why the former developer decided to generate images that high sophisticated
*/
unsigned char *Panel::CreatePanel(int width, int height)
{
unsigned char *buf;
int i, j;
buf = (unsigned char *) malloc(width * height * 4);
memset(buf, 0, width * height * 4);
#define pixel2(i, j, r, g, b, a) \
buf[(j) * width * 4 + (i) * 4 + 0] = r; \
buf[(j) * width * 4 + (i) * 4 + 1] = g; \
buf[(j) * width * 4 + (i) * 4 + 2] = b; \
buf[(j) * width * 4 + (i) * 4 + 3] = a;
#define pixel(i, j) \
pixel2((i), (j), 0x0, 0x8, 0x40, 0xff)
for (j = 1; j < height - 1; ++j)
{
for (i = 1; i < width - 1; ++i)
{
pixel2(i, j, 0x0, 0x8, 0x40, 0x80);
}
}
for (i = 3; i < width - 3; ++i)
{
pixel(i, 0);
pixel(i, height - 1);
}
for (i = 3; i < height - 3; ++i)
{
pixel(0, i);
pixel(width - 1, i);
}
// top left
pixel(1, 1);
pixel(2, 1);
pixel(1, 2);
// top right
pixel(width - 3, 1);
pixel(width - 2, 1);
pixel(width - 2, 2);
// bottom left
pixel(1, height - 3);
pixel(1, height - 2);
pixel(2, height - 2);
// bottom right
pixel(width - 3, height - 2);
pixel(width - 2, height - 2);
pixel(width - 2, height - 3);
#undef pixel
#undef pixel2
return buf;
}
int Panel::save(int width, int height)
{
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
unsigned char **lines;
int i;
char name[256];
unsigned char *buf;
Preferences &preferences = Preferences::getInstance();
sprintf(name, "%s/graphics/ui/panels/%dx%d.png",
preferences.getDestDir().c_str(), width, height);
CheckPath(name);
if (!(fp = fopen(name, "wb")))
{
fprintf(stderr, "%s:", name);
perror("Can't open file");
return 1;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
fclose(fp);
return 1;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return 1;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
// FIXME: must free buffers!!
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 1;
}
png_init_io(png_ptr, fp);
// zlib parameters
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
// prepare the file information
png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, 0,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
buf = CreatePanel(width, height);
// write the file header information
png_write_info(png_ptr, info_ptr); // write the file header information
// set transformation
// prepare image
lines = (unsigned char **) malloc(height * sizeof(*lines));
if (!lines)
{
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
free(buf);
return 1;
}
for (i = 0; i < height; ++i)
{
lines[i] = buf + i * width * 4;
}
png_write_image(png_ptr, lines);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
free(lines);
free(buf);
return 0;
}
| 3,331
|
C++
|
.cpp
| 141
| 20.333333
| 105
| 0.605188
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,128
|
NoValidPaletteException.cpp
|
Wargus_stargus/src/NoValidPaletteException.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include "NoValidPaletteException.h"
using namespace std;
const char *NoValidPaletteException::what() const throw()
{
static string s;
s = "Palette size doesn't fit to RGB, or RGBx/WPE or PCX2D: ";
s += to_string(m_size);
return static_cast <const char *>(s.c_str());
}
| 348
|
C++
|
.cpp
| 13
| 24.846154
| 64
| 0.728097
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,129
|
Pcx.cpp
|
Wargus_stargus/src/Pcx.cpp
|
/*
* Pcx.cpp
*
* Author: Andreas Volz
*/
// Local
#include <PngExporter.h>
#include "endian.h"
#include "Pcx.h"
#include "Storm.h"
#include "Hurricane.h"
#include "Logger.h"
// System
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
using namespace std;
static Logger logger = Logger("startool.Pcx");
Pcx::Pcx(std::shared_ptr<Hurricane> hurricane) :
Converter(hurricane), rawImage(0)
{
}
Pcx::Pcx(std::shared_ptr<Hurricane> hurricane, const std::string &arcfile) :
Converter(hurricane), rawImage(0)
{
load(arcfile);
}
Pcx::~Pcx()
{
free(rawImage);
}
bool Pcx::load(const std::string &arcfile)
{
bool result = true;
mRawData = mHurricane->extractDataChunk(arcfile);
if (mRawData)
{
free(rawImage);
extractHeader();
extractImage();
LOG4CXX_TRACE(logger, "load(): " + arcfile);
}
else
{
result = false;
}
return result;
}
bool Pcx::savePNG(Storage storage)
{
bool result = true;
if (mRawData)
{
PngExporter::saveRGB(storage.getFullPath(), *mPaletteImage, *mPalette, 0);
}
else
{
result = false;
}
return result;
}
std::shared_ptr<Palette> Pcx::getPalette()
{
return make_shared<Palette>(*mPalette);
}
Size Pcx::getSize()
{
Size imageSize;
if(mPaletteImage)
{
imageSize = mPaletteImage->getSize();
}
return imageSize;
}
std::shared_ptr<Palette> Pcx::mapIndexPalette(int length, int start, int index)
{
std::shared_ptr<Palette> palette(mPalette);
if (mPaletteImage && palette)
{
for (int i = 0; i < length; i++)
{
int rel_index = i + (index * length);
int start_pal_dest = start + i;
unsigned char color_index = mPaletteImage->at(rel_index);
Color &image_color = mPalette->at(color_index);
palette->at(start_pal_dest) = image_color;
}
}
return palette;
}
std::shared_ptr<Palette2D> Pcx::map2DPalette()
{
std::shared_ptr<Palette2D> palette2D;
if (mPaletteImage && mPalette)
{
// check magic size of the special 2D palette format
if (mPaletteImage->getSize().getWidth() == 256)
{
palette2D = make_shared<Palette2D>(mPaletteImage->getSize().getHeight());
for (int x = 0; x < mPaletteImage->getSize().getWidth()-1; x++)
{
for (int y = 0; y < mPaletteImage->getSize().getHeight()-1; y++)
{
// FIXME: there was a bug in getPalettePixel() that y was decremented 1. After fixing it the output was ugly
// now I substract here y-1 before and now alpha graphics (e.g. fire) look fine. I've to check the algorithm later again
int y_mod = (y > 0) ? (y-1) : 0;
unsigned char color_index = mPaletteImage->at(Pos(x, y_mod));
if(color_index != 255)
{
Color image_color = mPalette->at(color_index);
palette2D->at(x, y) = image_color;
}
else
{
Color trans_color(0, 0, 0);
palette2D->at(x, y) = trans_color;
}
}
}
}
}
return palette2D;
}
void Pcx::extractHeader()
{
if (mRawData)
{
struct PCXheader pcxh;
memcpy(&pcxh, mRawData->getDataPointer(), sizeof(struct PCXheader));
pcxh.Xmin = ConvertLE16(pcxh.Xmin);
pcxh.Ymin = ConvertLE16(pcxh.Ymin);
pcxh.Xmax = ConvertLE16(pcxh.Xmax);
pcxh.Ymax = ConvertLE16(pcxh.Ymax);
pcxh.BytesPerLine = ConvertLE16(pcxh.BytesPerLine);
int width = pcxh.Xmax - pcxh.Xmin + 1;
int height = pcxh.Ymax - pcxh.Ymin + 1;
mPaletteImage = make_shared<PaletteImage>(Size(width, height));
}
}
void Pcx::extractImage()
{
int y;
int count;
unsigned char *dest = NULL;
unsigned char ch = 0;
unsigned char *imageParserPos = nullptr;
size_t pos = 0;
if (mRawData)
{
rawImage = (unsigned char *) malloc(mPaletteImage->getSize().getWidth() * mPaletteImage->getSize().getHeight());
imageParserPos = mRawData->getDataPointer() + sizeof(struct PCXheader);
for (y = 0; y < mPaletteImage->getSize().getHeight(); ++y)
{
count = 0;
dest = rawImage + y * mPaletteImage->getSize().getWidth();
for (int i = 0; i < mPaletteImage->getSize().getWidth(); ++i)
{
if (!count)
{
ch = *imageParserPos++;
if ((ch & 0xc0) == 0xc0)
{
count = ch & 0x3f;
ch = *imageParserPos++;
}
else
{
count = 1;
}
}
dest[i] = ch;
mPaletteImage->at(pos) = ch;
pos++;
--count;
}
}
// extract palette =>
mPalette = make_shared<Palette>();
do
{
ch = *imageParserPos++;
}
while (ch != 0x0c); // search the 'magic ID' that shows the start of RGB information next
// copy RGB information to destination
for (int i = 0; i < RGB_SIZE; i += 3)
{
unsigned char red = *imageParserPos++;
unsigned char green = *imageParserPos++;
unsigned char blue = *imageParserPos++;
Color rgb(red, green, blue);
mPalette->at(i/3) = rgb;
}
}
}
| 5,071
|
C++
|
.cpp
| 195
| 21.102564
| 130
| 0.617264
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,130
|
pacman.cpp
|
Wargus_stargus/src/pacman.cpp
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// system
#include <cstring>
#include <cstdlib>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
// project
#include "pacman.h"
#include "FileNotFoundException.h"
#include "platform.h"
using namespace std;
namespace pacman {
const std::string searchFile(const std::string &data)
{
vector <string> name_vector;
#ifdef HAVE_CONFIG_H
// search in the package directory (e.g. /usr/share/<package>
name_vector.push_back(string(PACKAGE_DATA_DIR) + data);
// if this still fails we assume the developer case and search the data in absolute source folder
name_vector.push_back(string(PACKAGE_SOURCE_DIR) + data);
#endif
// do this as last as in config.h case relative path is not desired
name_vector.push_back(data);
const string &file = statFile(name_vector);
if (file.empty())
{
throw FileNotFoundException(data);
}
return file;
}
const std::string searchDir(const std::string &data)
{
const string &file = searchFile(data);
fs::path p(file);
return p.remove_filename().string();
}
const std::string statFile(std::vector <std::string> &name_vector)
{
struct stat buf;
for (unsigned int i = 0; i < name_vector.size(); i++)
{
string &try_name = name_vector[i];
bool found = !(stat(try_name.c_str(), &buf));
//cout << "try_name: " << try_name << endl;
if (found)
{
return try_name;
}
}
return "";
}
}
| 1,451
|
C++
|
.cpp
| 55
| 23.654545
| 99
| 0.701818
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,131
|
Storm.cpp
|
Wargus_stargus/src/Storm.cpp
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef _MSC_VER
#define DEBUG _DEBUG
#define PATH_MAX _MAX_PATH
#include <direct.h>
#include <io.h>
#else
#include <limits.h>
#include <unistd.h>
#endif
#include <ctype.h>
#include <iostream>
#include <zlib.h>
#include <StormLib.h>
#include "Storm.h"
#include "FileUtil.h"
using namespace std;
Storm::Storm() :
mMpqHandle(nullptr)
{
}
Storm::Storm(const std::string &archiveName) :
mMpqHandle(nullptr)
{
openArchive(archiveName);
}
Storm::~Storm()
{
closeArchive();
}
bool Storm::openArchive(const std::string &archiveName)
{
bool result = true;
// close it in case it's still open
closeArchive();
// Open an archive, e.g. "d2music.mpq"
if (!SFileOpenArchive(archiveName.c_str(), 0, STREAM_FLAG_READ_ONLY, &mMpqHandle))
{
result = false;
}
else
{
mArchiveName = archiveName;
}
return result;
}
void Storm::closeArchive()
{
if (mMpqHandle != nullptr)
{
SFileCloseArchive(mMpqHandle);
mArchiveName.clear();
}
}
bool Storm::extractMemory(const std::string &archivedFile, unsigned char **szEntryBufferPrt, size_t *bufferLen)
{
int nError = ERROR_SUCCESS;
unsigned char *szEntryBuffer = nullptr;
HANDLE hFile = nullptr; // Archived file handle
bool result = true;
// Open a file in the archive, e.g. "data\global\music\Act1\tristram.wav"
if (nError == ERROR_SUCCESS)
{
if (!SFileOpenFileEx(mMpqHandle, archivedFile.c_str(), 0, &hFile))
nError = GetLastError();
}
int i = 0;
size_t len = 0;
// Read the file from the archive
if (nError == ERROR_SUCCESS)
{
char szBuffer[0x10000];
szEntryBuffer = (unsigned char *) malloc(sizeof(szBuffer)); // TODO: this might me useless and then free() could be avoid below
DWORD dwBytes = 1;
while (dwBytes > 0)
{
SFileReadFile(hFile, szBuffer, sizeof(szBuffer), &dwBytes, NULL);
if (dwBytes > 0)
{
len = len + dwBytes;
szEntryBuffer = (unsigned char *) realloc(szEntryBuffer, len);
memcpy(szEntryBuffer + (i * sizeof(szBuffer)), szBuffer, dwBytes);
}
i++;
}
}
if (bufferLen != NULL)
{
*bufferLen = len;
}
if (hFile != NULL)
SFileCloseFile(hFile);
if (nError != ERROR_SUCCESS)
{
result = false;
// in case of problem free what ever has been allocated
free(szEntryBuffer);
szEntryBuffer = nullptr;
}
*szEntryBufferPrt = szEntryBuffer;
return result;
}
bool Storm::extractFile(const std::string &archivedFile, const std::string &extractedName, bool compress)
{
HANDLE hFile = nullptr; // Archived file handle
FILE *file = nullptr; // Disk file handle
gzFile gzfile = nullptr; // Compressed file handle
int nError = ERROR_SUCCESS;
bool result = true;
// Open a file in the archive, e.g. "data\global\music\Act1\tristram.wav"
if (nError == ERROR_SUCCESS)
{
if (!SFileOpenFileEx(mMpqHandle, archivedFile.c_str(), 0, &hFile))
nError = GetLastError();
}
// Create the target file
if (nError == ERROR_SUCCESS)
{
CheckPath(extractedName);
if (compress)
{
gzfile = gzopen(extractedName.c_str(), "wb9");
}
else
{
file = fopen(extractedName.c_str(), "wb");
}
}
// Read the file from the archive
if (nError == ERROR_SUCCESS)
{
char szBuffer[0x10000];
DWORD dwBytes = 1;
while (dwBytes > 0)
{
SFileReadFile(hFile, szBuffer, sizeof(szBuffer), &dwBytes, NULL);
if (dwBytes > 0)
{
if (compress)
{
if(gzfile)
{
gzwrite(gzfile, szBuffer, dwBytes);
}
}
else
{
if(file)
{
fwrite(szBuffer, 1, dwBytes, file);
}
}
}
}
}
// Cleanup and exit
if (file != NULL)
{
fclose(file);
}
if (gzfile != NULL)
{
gzclose(gzfile);
}
if (hFile != NULL)
SFileCloseFile(hFile);
if (nError != ERROR_SUCCESS)
result = false;
return result;
}
unsigned int Storm::getRecordCount(const std::string &archivedFile, unsigned int recordsize)
{
// TODO: implement
return 0;
}
| 4,253
|
C++
|
.cpp
| 180
| 19.627778
| 131
| 0.645313
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,132
|
Widgets.cpp
|
Wargus_stargus/src/Widgets.cpp
|
/*
* Widget.cpp
*
* Author: Andreas Volz
*/
// project
#include <Palette.h>
#include <PngExporter.h>
#include "Widgets.h"
#include "Storm.h"
#include "Preferences.h"
#include "FileUtil.h"
#include "pacman.h"
// system
#include <fstream>
#include <iostream>
using namespace std;
Widgets::Widgets(std::shared_ptr<Hurricane> hurricane) :
Grp(hurricane)
{
}
Widgets::~Widgets()
{
}
bool Widgets::convert(const std::string &arcfile, Storage filename, json &frameExtractJson)
{
bool result = true;
std::shared_ptr<DataChunk> dcGrp = mHurricane->extractDataChunk(arcfile);
std::vector<char> GrpVec = dcGrp->getCharVector();
mGRPImage.LoadImage(&GrpVec, true); // true: no duplicate widgets needed
CheckPath(filename.getFullPath());
if(dcGrp)
{
//cout << frameExtractJson << endl; // prints json object to screen
//vector<string> frameSingleNames;
for(auto &array : frameExtractJson)
{
//int frame_id = array.at("frame");
string name = array.at("name");
nlohmann::json frameArray = array.at("frame");
int frameStitching = 0;
vector<int> stitchedFrames;
for(auto frame : frameArray)
{
//cout << "frame: " << frame << endl;
stitchedFrames.push_back(frame);
frameStitching++;
}
if(frameStitching == 1)
{
//frameSingleNames.push_back(name);
mGRPImage.SaveSinglePNG(filename.getFullPath() + "/" + name, *stitchedFrames.begin(), *stitchedFrames.begin()+1, true);
}
else if(frameStitching > 1)
{
mGRPImage.SaveStitchedPNG(filename.getFullPath() + "/" + name, stitchedFrames, 0, true);
}
else
{
cerr << "something wrong with frame array!" << endl;
}
}
//mGRPImage.SaveSinglePNG(filename.getFullPath(), frameSingleNames, 0, mGRPImage.getNumberOfFrames(), true);
}
return result;
}
| 1,897
|
C++
|
.cpp
| 66
| 24.287879
| 127
| 0.665561
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,133
|
Font.cpp
|
Wargus_stargus/src/Font.cpp
|
/*
* Font.cpp
*
* Author: Andreas Volz
*/
// Local
#include <Palette.h>
#include <PngExporter.h>
#include "Font.h"
#include "endian.h"
#include "FileUtil.h"
#include "Storm.h"
#include "Preferences.h"
#include "StringUtil.h"
#include "Logger.h"
// C
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
using namespace std;
static Logger logger = Logger("startool.Font");
Font::Font(std::shared_ptr<Hurricane> hurricane) :
mHurricane(hurricane)
{
}
Font::~Font()
{
}
/**
** Convert a font to PNG image format.
**
** @return true if everything is ok
*/
bool Font::convert(const std::string &arcfile, Storage file)
{
unsigned char *image;
int w;
int h;
bool result = true;
LOG4CXX_TRACE(logger, "convert:" + arcfile + "," + file);
shared_ptr<DataChunk> data = mHurricane->extractDataChunk(arcfile);
if (data && mPalette)
{
std::shared_ptr<DataChunk> datachunk = mPalette->createDataChunk();
image = Font::convertImage(data->getDataPointer(), &w, &h);
CheckPath(file.getFullPath());
DataChunk dc_image(&image, w * h);
PaletteImage palImage(dc_image, Size(w, h));
PngExporter::save(file.getFullPath(), palImage, mPalette, 255);
}
return result;
}
void Font::setPalette(std::shared_ptr<AbstractPalette> pal)
{
mPalette = pal;
}
typedef struct _FontHeader
{
char name[5]; // [0-4] Always is "FONT"
uint8_t lowIndex; // Index of the first letter in file
uint8_t highIndex; // Index of the last letter in file
uint8_t maxWidth; // Maximum width
uint8_t maxHeight; // Maximum height
//DWORD Unk1; // Unknown / Unused
} FontHeader;
// size of this header struct has to be 4xbyte!
typedef struct _FontLetterHeader
{
uint8_t width; // Width of the letter
uint8_t height; // Height of the letter
uint8_t xOffset; // X Offset for the topleft corner of the letter.
uint8_t yOffset; // Y Offset for the topleft corner of the letter.
} FontLetterHeader;
unsigned char *Font::convertImage(unsigned char *start, int *wp, int *hp)
{
char buf[1024];
FontHeader header;
unsigned char *bp = nullptr;
unsigned char *image = nullptr;
unsigned char *dp = nullptr;
unsigned int *offsets = nullptr;
int image_width = 0;
int image_height = 0;
LOG4CXX_DEBUG(logger, "convertImage");
bp = start;
header.name[0] = FetchByte(bp);
header.name[1] = FetchByte(bp);
header.name[2] = FetchByte(bp);
header.name[3] = FetchByte(bp);
header.name[4] = '\0';
header.lowIndex = FetchByte(bp);
header.highIndex = FetchByte(bp);
header.maxWidth = FetchByte(bp);
header.maxHeight = FetchByte(bp);
unsigned int letterCount = header.highIndex - header.lowIndex;
if (!strncmp(header.name, "FONT", 4))
{
sprintf(buf, "li:%i / hi:%i / mw:%i / mh:%i", header.lowIndex,
header.highIndex, header.maxWidth, header.maxHeight);
LOG4CXX_DEBUG(logger, string("FONT header found: ") + buf);
//bp += 2; // DWORD unused
image_width = header.maxWidth;
image_height = letterCount * header.maxHeight;
sprintf(buf, "w:%i / h:%i", image_width, image_height);
LOG4CXX_DEBUG(logger, string("Image size: ") + buf);
// calculate the offsets for each font letter header
offsets = (unsigned int *) malloc(letterCount * sizeof(FontLetterHeader));
for (unsigned int i = 0; i < letterCount; ++i)
{
offsets[i] = FetchLE32(bp);
}
// allocate the memory to fill with raw image data
image = (unsigned char *) malloc(image_width * image_height);
if (!image)
{
LOG4CXX_FATAL(logger, "Can't allocate image memory");
}
// Give image a transparent background
memset(image, 255, image_width * image_height);
// do this for all letters
for (unsigned int i = 0; i < letterCount; i++)
{
if (!offsets[i])
{
continue;
}
FontLetterHeader letter;
// set pointer to each letter header start...
bp = start + offsets[i];
letter.width = FetchByte(bp);
letter.height = FetchByte(bp);
letter.xOffset = FetchByte(bp);
letter.yOffset = FetchByte(bp);
sprintf(buf, "%i# w:%i / h:%i / x:%i / y:%i", i, letter.width,
letter.height, letter.xOffset, letter.yOffset);
LOG4CXX_DEBUG(logger, string("FontLetterRaw: ") + buf);
dp = image + letter.xOffset + letter.yOffset * header.maxWidth
+ i * (header.maxWidth * header.maxHeight);
int w = 0;
int h = 0;
// copy all data from each letter and convert it
// who ever coded this algorithm didn't document it - but it seems to work!!
for (;;)
{
int ctrl;
ctrl = FetchByte(bp)
;
w += (ctrl >> 3) & 0x1F;
if (w >= letter.width)
{
w -= letter.width;
++h;
if (h >= letter.height)
{
break;
}
}
dp[h * header.maxWidth + w] = ctrl & 0x07;
++w;
if (w >= letter.width)
{
w -= letter.width;
++h;
if (h >= letter.height)
{
break;
}
}
}
}
}
else
{
LOG4CXX_WARN(logger, "No Font Header found!");
}
LOG4CXX_TRACE(logger, "Exported font letter number: " + to_string(letterCount));
*wp = header.maxWidth;
*hp = header.maxHeight * letterCount;
// free the offset memory as it's not longer used
free(offsets);
return image;
}
| 5,463
|
C++
|
.cpp
| 183
| 25.125683
| 82
| 0.636884
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,134
|
GRPImage.cpp
|
Wargus_stargus/src/libgrp/GRPImage/GRPImage.cpp
|
#include "GRPImage.hpp"
#include "PngExporter.h"
#include "StringUtil.h"
#include <string.h>
#include <iostream>
#include <cmath>
#include <sstream>
#include <unordered_map>
using namespace std;
//#define VERBOSE 10 // debug
GRPImage::GRPImage() :
mCurrentPalette(nullptr),
mNumberOfFrames(0),
mMaxImageWidth(0),
mMaxImageHeight(0),
mUncompressed(false)
{
}
GRPImage::GRPImage(std::vector<char> *inputImage, bool removeDuplicates) :
mCurrentPalette(nullptr),
mNumberOfFrames(0),
mMaxImageWidth(0),
mMaxImageHeight(0),
mUncompressed(false)
{
LoadImage(inputImage, removeDuplicates);
}
GRPImage::GRPImage(std::string filePath, bool removeDuplicates) :
mCurrentPalette(nullptr),
mNumberOfFrames(0),
mMaxImageWidth(0),
mMaxImageHeight(0),
mUncompressed(false)
{
LoadImage(filePath, removeDuplicates);
}
GRPImage::~GRPImage()
{
CleanGRPImage();
}
bool GRPImage::DetectUncompressed(std::vector<char> *inputImage)
{
bool uncompressed = false;
std::vector<char>::iterator currentDataPosition = inputImage->begin();
// jump over the basic GRP header info
currentDataPosition += 2;
// jump over the maximum image width & height
currentDataPosition += 2;
currentDataPosition += 2;
//Temporary image demension placeholders
uint8_t tempWidth = 0;
uint8_t tempHeight = 0;
uint32_t tempDataOffset = 0;
uint32_t firstOffset = 0;
int imagePayload = 0;
//Create a hash table to stop the creation of duplicates
std::unordered_map<uint32_t, bool> uniqueGRPImages;
std::unordered_map<uint32_t, bool>::const_iterator uniqueGRPCheck;
//Load each GRP Header into a GRPFrame & Allocate
for(int currentGRPFrame = 0; currentGRPFrame < mNumberOfFrames; currentGRPFrame++)
{
//Jump over the image xOffset
currentDataPosition += 1;
//Jump over the image yOffset
currentDataPosition += 1;
//Read in the image width
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &tempWidth);
currentDataPosition += 1;
//Read in the image height
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &tempHeight);
currentDataPosition += 1;
//Read in the image dataOffset
std::copy(currentDataPosition, (currentDataPosition + 4),(char *) &tempDataOffset);
currentDataPosition += 4;
uniqueGRPCheck = uniqueGRPImages.find(tempDataOffset);
if(uniqueGRPCheck == uniqueGRPImages.end())
{
imagePayload += tempWidth * tempHeight;
}
uniqueGRPImages.insert(std::make_pair(tempDataOffset, true));
if(firstOffset == 0)
{
firstOffset = tempDataOffset;
}
}
//cout << "completeImageSize: " << to_string(imagePayload + firstOffset) << endl;
if(firstOffset + imagePayload == inputImage->size())
{
uncompressed = true;
}
else
{
uncompressed = false;
}
return uncompressed;
}
void GRPImage::DecodeHeader(std::vector<char> *inputImage)
{
std::vector<char>::iterator currentDataPosition = inputImage->begin();
//Get basic GRP header info
std::copy(currentDataPosition,(currentDataPosition + 2),(char *) &mNumberOfFrames);
currentDataPosition += 2;
//Get the maximum image width & height
std::copy(currentDataPosition, (currentDataPosition + 2),(char *) &mMaxImageWidth);
currentDataPosition += 2;
std::copy(currentDataPosition, (currentDataPosition + 2),(char *) &mMaxImageHeight);
currentDataPosition += 2;
}
void GRPImage::LoadImage(std::vector<char> *inputImage, bool removeDuplicates)
{
CleanGRPImage();
std::vector<char>::iterator currentDataPosition = inputImage->begin();
DecodeHeader(inputImage);
mUncompressed = DetectUncompressed(inputImage);
// jump over the basic GRP header info
currentDataPosition += 2;
// jump over the maximum image width & height
currentDataPosition += 2;
currentDataPosition += 2;
#if VERBOSE >= 2
std::cout << "GRP Image Number of Frames: " << mNumberOfFrames << " maxWidth: " << mMaxImageWidth << " maxHeight: " << mMaxImageHeight << '\n';
#endif
//Temporary image demension placeholders
uint8_t tempValue1 = 0;
uint8_t tempValue2 = 0;
uint32_t tempDataOffset = 0;
//Create a hash table to stop the creation of duplicates
std::unordered_map<uint32_t, bool> uniqueGRPImages;
std::unordered_map<uint32_t, bool>::const_iterator uniqueGRPCheck;
//int bestWidth = 0;
//int bestHeight = 0;
//Load each GRP Header into a GRPFrame & Allocate
for(int currentGRPFrame = 0; currentGRPFrame < mNumberOfFrames; currentGRPFrame++)
{
GRPFrame *currentImageFrame = new GRPFrame;
//Read in the image xOffset
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &tempValue1);
currentDataPosition += 1;
//Read in the image yOffset
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &tempValue2);
currentDataPosition += 1;
currentImageFrame->SetImageOffsets(tempValue1, tempValue2);
//Read in the image width
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &tempValue1);
currentDataPosition += 1;
//Read in the image height
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &tempValue2);
currentDataPosition += 1;
currentImageFrame->SetImageSize(tempValue1, tempValue2);
//Read in the image dataOffset
std::copy(currentDataPosition, (currentDataPosition + 4),(char *) &tempDataOffset);
currentDataPosition += 4;
currentImageFrame->SetDataOffset(tempDataOffset);
#if VERBOSE >= 2
std::cout << "Current Frame: " << currentGRPFrame << " Width: " << (int) currentImageFrame->GetImageWidth() << " Height: "
<< (int) currentImageFrame->GetImageHeight() << "\nxPosition: " << (int) currentImageFrame->GetXOffset()
<< " yPosition: " << (int) currentImageFrame->GetYOffset() << " with offset " << (int)currentImageFrame->GetDataOffset() << '\n';
#endif
uniqueGRPCheck = uniqueGRPImages.find(currentImageFrame->GetDataOffset());
if(removeDuplicates && (uniqueGRPCheck != uniqueGRPImages.end()))
{
// in case of not included duplicates delete the frame
delete currentImageFrame;
}
else
{
//The GRPImage is unique save in the unordered set
uniqueGRPImages.insert(std::make_pair<uint32_t,bool>(currentImageFrame->GetDataOffset(),true));
//Decode Frame here
if(mUncompressed)
{
DecodeGRPFrameDataUncompressed(inputImage, currentImageFrame);
}
else
{
DecodeGRPFrameData(inputImage, currentImageFrame);
}
mImageFrames.push_back(currentImageFrame);
}
}
if (removeDuplicates)
{
mNumberOfFrames = mImageFrames.size();
}
}
void GRPImage::LoadImage(std::string filePath, bool removeDuplicates)
{
DataChunk dcImage;
dcImage.read(filePath);
vector<char> vecImage = dcImage.getCharVector();
LoadImage(&vecImage, removeDuplicates);
}
void GRPImage::DecodeGRPFrameDataUncompressed(std::vector<char> *inputData, GRPFrame *targetFrame)
{
if(targetFrame == NULL || (targetFrame->frameData.size() == 0))
{
GRPImageNoFrameLoaded noFrameLoaded;
noFrameLoaded.SetErrorMessage("No GRP Frame is loaded");
}
if(mCurrentPalette == NULL)
{
GRPImageNoLoadedPaletteSet noPaletteLoaded;
noPaletteLoaded.SetErrorMessage("No palette has been set or loaded");
}
//Seek to the Row offset data
std::vector<char>::iterator currentDataPosition = inputData->begin();
currentDataPosition += targetFrame->GetDataOffset();
//The currentRow (x coordinate) that the decoder is at, it is used to
//set the image position.
int currentProcessingRow = 0;
//The initial byte of data from the GRPFile
//It is often the operation that will be done
//of the proceding data
uint8_t rawPacket;
//The struct keeps a (X,Y) coordinates to the position
//of the referenced color to allow for drawing on the screen
//or Imagemagick to convert.
UniquePixel currentUniquePixel;
//Goto each row and process the row data
for(int currentProcessingHeight = 0; currentProcessingHeight < targetFrame->GetImageHeight(); currentProcessingHeight++)
{
#if VERBOSE >= 2
//std::cout << "Current row offset is: " << (targetFrame->GetDataOffset() + (imageRowOffsets.at(currentProcessingHeight))) << '\n';
#endif
//Seek to the point of the first byte in the rowData from the
//1.Skip over to the Frame data
//2.Skip over the size of the targetFrame->size() last time read bytes
currentDataPosition = inputData->begin() + targetFrame->frameData.size();
currentDataPosition += (targetFrame->GetDataOffset());
currentProcessingRow = 0;
while(currentProcessingRow < targetFrame->GetImageWidth())
{
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &rawPacket);
currentDataPosition += 1;
currentUniquePixel.xPosition = currentProcessingRow;
currentUniquePixel.yPosition = currentProcessingHeight;
currentUniquePixel.colorPaletteReference = rawPacket;
targetFrame->frameData.push_back(currentUniquePixel);
currentProcessingRow++;
}
}
#if VERBOSE >= 5
std::cout << "Frame data is size: " << targetFrame->frameData.size() << '\n';
for(std::list<UniquePixel>::iterator it = targetFrame->frameData.begin(); it != targetFrame->frameData.end(); it++)
{
std::cout << '(' << it->xPosition << ',' << it->yPosition << ") = " << (int) it->colorPaletteReference << '\n';
}
#endif
}
void GRPImage::DecodeGRPFrameData(std::vector<char> *inputData, GRPFrame *targetFrame)
{
if(targetFrame == NULL || (targetFrame->frameData.size() == 0))
{
GRPImageNoFrameLoaded noFrameLoaded;
noFrameLoaded.SetErrorMessage("No GRP Frame is loaded");
}
if(mCurrentPalette == NULL)
{
GRPImageNoLoadedPaletteSet noPaletteLoaded;
noPaletteLoaded.SetErrorMessage("No palette has been set or loaded");
}
//Seek to the Row offset data
std::vector<char>::iterator currentDataPosition = inputData->begin();
currentDataPosition += targetFrame->GetDataOffset();
//Create a vector of all the Image row offsets
std::vector<uint16_t> imageRowOffsets;
imageRowOffsets.resize(targetFrame->GetImageHeight());
//Read in the ImageRow offsets
for (int currentReadingRowOffset = 0; currentReadingRowOffset < targetFrame->GetImageHeight(); currentReadingRowOffset++)
{
std::copy(currentDataPosition, (currentDataPosition + 2),(char *) &imageRowOffsets.at(currentReadingRowOffset));
currentDataPosition += 2;
}
//The currentRow (x coordinate) that the decoder is at, it is used to
//set the image position.
int currentProcessingRow = 0;
//The initial byte of data from the GRPFile
//It is often the operation that will be done
//of the proceding data
uint8_t rawPacket;
//The references to a particular color
uint8_t convertedPacket;
//The struct keeps a (X,Y) coordinates to the position
//of the referenced color to allow for drawing on the screen
//or Imagemagick to convert.
UniquePixel currentUniquePixel;
//Goto each row and process the row data
for(int currentProcessingHeight = 0; currentProcessingHeight < targetFrame->GetImageHeight(); currentProcessingHeight++)
{
#if VERBOSE >= 2
std::cout << "Current row offset is: " << (targetFrame->GetDataOffset() + (imageRowOffsets.at(currentProcessingHeight))) << '\n';
#endif
//Seek to the point of the first byte in the rowData from the
//1.Skip over to the Frame data
//2.Skip over by the Row offset mentioned in the list
currentDataPosition = inputData->begin();
currentDataPosition += (targetFrame->GetDataOffset() + imageRowOffsets.at(currentProcessingHeight));
currentProcessingRow = 0;
while(currentProcessingRow < targetFrame->GetImageWidth())
{
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &rawPacket);
currentDataPosition += 1;
if(!(rawPacket & 0x80))
{
//Repeat Operation (The first byte indicates a repeat pixel operation)
//The next byte indicates how far down the row to repeat.
if(rawPacket & 0x40)
{
rawPacket &= 0x3f;
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &convertedPacket);
currentDataPosition += 1;
//Set the Player color (Not implemented yet :|
//covertedPacket = tableof unitColor[ colorbyte+gr_gamenr];
int operationCounter = rawPacket;
currentUniquePixel.xPosition = currentProcessingRow;
do
{
currentUniquePixel.yPosition = currentProcessingHeight;
currentUniquePixel.colorPaletteReference = convertedPacket;
targetFrame->frameData.push_back(currentUniquePixel);
currentUniquePixel.xPosition++;
}
while (--operationCounter);
currentProcessingRow += rawPacket;
}
else
{
//Copy Pixel Operation, and how many pixels to copy directly
int operationCounter = rawPacket;
if(operationCounter > 0)
{
do
{
std::copy(currentDataPosition, (currentDataPosition + 1),(char *) &convertedPacket);
currentDataPosition += 1;
currentUniquePixel.xPosition = currentProcessingRow;
currentUniquePixel.yPosition = currentProcessingHeight;
currentUniquePixel.colorPaletteReference = convertedPacket;
targetFrame->frameData.push_back(currentUniquePixel);
currentProcessingRow++;
}
while (--operationCounter);
}
}
}
else
{
//Skip the next "rawPacket" # of pixels
rawPacket &= 0x7f;
currentProcessingRow += rawPacket;
}
}
}
#if VERBOSE >= 5
std::cout << "Frame data is size: " << targetFrame->frameData.size() << '\n';
for(std::list<UniquePixel>::iterator it = targetFrame->frameData.begin(); it != targetFrame->frameData.end(); it++)
{
std::cout << '(' << it->xPosition << ',' << it->yPosition << ") = " << (int) it->colorPaletteReference << '\n';
}
#endif
}
uint16_t GRPImage::getNumberOfFrames() const
{
return mNumberOfFrames;
}
uint16_t GRPImage::getMaxImageWidth() const
{
return mMaxImageWidth;
}
uint16_t GRPImage::getMaxImageHeight() const
{
return mMaxImageHeight;
}
void GRPImage::SetColorPalette(std::shared_ptr<AbstractPalette> selectedColorPalette)
{
if(selectedColorPalette)
mCurrentPalette = selectedColorPalette;
}
void GRPImage::SaveStitchedPNG(const std::string &outFilePath, int startingFrame, int endingFrame, unsigned int imagesPerRow, bool rgba)
{
vector<int> frameEnumarator;
for(int i = startingFrame; i < endingFrame; i++)
{
frameEnumarator.push_back(i);
}
SaveStitchedPNG(outFilePath, frameEnumarator, imagesPerRow, rgba);
}
void GRPImage::SaveStitchedPNG(const std::string &outFilePath, std::vector<int> frameEnumerator, unsigned int imagesPerRow, bool rgba)
{
if(!mCurrentPalette)
{
GRPImageNoLoadedPaletteSet noPalette;
noPalette.SetErrorMessage("No loaded set");
}
shared_ptr<PaletteImage> paletteImage;
// limit the 'imagePerRow' input parameter in both directions to something useful
if((imagesPerRow >= frameEnumerator.size()) || (imagesPerRow == 0))
{
imagesPerRow = frameEnumerator.size();
}
Color currentPalettePixel;
std::stringstream fileOutPath;
int currentImageDestinationColumn = 0;
unsigned int currentImageDestinationRow = 0;
int bestWidth = 0;
int bestHeight = 0;
for(int currentProcessingFrame : frameEnumerator)
{
GRPFrame *currentImageFrame = mImageFrames.at(currentProcessingFrame);
// calculate the best width/height for that image (only for uncompressed or only partly exported)
if((mUncompressed) || (frameEnumerator.size() != mNumberOfFrames))
{
if (currentImageFrame->GetXOffset() + currentImageFrame->GetImageWidth() > bestWidth)
{
bestWidth = currentImageFrame->GetXOffset() + currentImageFrame->GetImageWidth();
}
if (currentImageFrame->GetYOffset() + currentImageFrame->GetImageHeight() > bestHeight)
{
bestHeight = currentImageFrame->GetYOffset() + currentImageFrame->GetImageHeight();
}
mMaxImageWidth = bestWidth;
mMaxImageHeight = bestHeight;
}
}
int image_width = (mMaxImageWidth * imagesPerRow);
int image_height = (mMaxImageHeight * (ceil( (float)frameEnumerator.size()/imagesPerRow)));
// create the complete image with all stitched small images
paletteImage = make_shared<PaletteImage>(Size(image_width, image_height));
for(int currentProcessingFrame : frameEnumerator)
{
GRPFrame *currentFrame = mImageFrames.at(currentProcessingFrame);
//If a row in a stitched image is complete, move onto the next row
if(currentImageDestinationRow >= imagesPerRow)
{
currentImageDestinationColumn++;
currentImageDestinationRow = 0;
}
//Start appling the pixels with the refence colorpalettes
for (std::list<UniquePixel>::iterator currentProcessPixel = currentFrame->frameData.begin(); currentProcessPixel != currentFrame->frameData.end(); currentProcessPixel++)
{
Pos pixel_pos((currentFrame->GetXOffset() + currentProcessPixel->xPosition) + (mMaxImageWidth * currentImageDestinationRow),
(currentFrame->GetYOffset() + currentProcessPixel->yPosition) + (mMaxImageHeight * currentImageDestinationColumn) );
paletteImage->at(pixel_pos) = currentProcessPixel->colorPaletteReference;
}
currentImageDestinationRow++;
}
//Now that all the pixels are in place, lets write the result to disk
PngExporter::save(outFilePath, *paletteImage, mCurrentPalette, 0, rgba);
}
void GRPImage::SaveSinglePNG(const std::string &outFilePath, int startingFrame, int endingFrame, bool rgba)
{
SaveSinglePNG(outFilePath, std::vector<std::string>(), startingFrame, endingFrame, rgba);
}
void GRPImage::SaveSinglePNG(const std::string &outFilePath, const std::vector<std::string> &fileNames, int startingFrame, int endingFrame, bool rgba)
{
if(!mCurrentPalette)
{
GRPImageNoLoadedPaletteSet noPalette;
noPalette.SetErrorMessage("No loaded set");
}
shared_ptr<PaletteImage> paletteImage;
Color currentPalettePixel;
std::stringstream fileOutPath;
unsigned int i = 0;
for(int currentProcessingFrame = startingFrame; currentProcessingFrame < endingFrame; ++currentProcessingFrame)
{
GRPFrame *currentFrame = mImageFrames.at(currentProcessingFrame);
// create a image for each frame
//cout << "image size: " << to_string(currentFrame->GetImageWidth()) << "/" << to_string(currentFrame->GetImageHeight()) << endl;
paletteImage = make_shared<PaletteImage>(Size(currentFrame->GetImageWidth(), currentFrame->GetImageHeight()));
//Start appling the pixels with the refence colorpalettes
for (std::list<UniquePixel>::iterator currentProcessPixel = currentFrame->frameData.begin(); currentProcessPixel != currentFrame->frameData.end(); currentProcessPixel++)
{
Pos pixel_pos((currentProcessPixel->xPosition),
(currentProcessPixel->yPosition));
//cout << "put color to: " << to_string(pixel_pos.getX()) << "/" << to_string(pixel_pos.getY()) << endl;
paletteImage->at(pixel_pos) = currentProcessPixel->colorPaletteReference;
}
//It's time to write the current frame to a file
string frameOutput = outFilePath;
// if the name vector is empty use the string %d replacer
if(fileNames.empty())
{
replaceString("%d", to_string(currentProcessingFrame), frameOutput);
}
else
{
if(i < fileNames.size())
{
frameOutput += "/" + fileNames.at(i);
}
else
{
// name fallback in case the input doesn't contain a name
frameOutput += "/" + to_string(i) + ".png";
}
}
PngExporter::save(frameOutput, *paletteImage, mCurrentPalette, 0, rgba);
i++;
}
}
void GRPImage::CleanGRPImage()
{
for(unsigned int i = 0; i < mImageFrames.size(); i++)
{
GRPFrame *frame = mImageFrames.at(i);
delete frame;
}
mImageFrames.resize(0);
}
| 20,249
|
C++
|
.cpp
| 510
| 34.931373
| 173
| 0.715662
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,135
|
GRPException.cpp
|
Wargus_stargus/src/libgrp/Exceptions/GRPException.cpp
|
#include "GRPException.hpp"
void GRPException::SetErrorMessage(const std::string &errorMessage)
{
humanReadableError = "GRPException: ";
humanReadableError.append(errorMessage);
}
std::string GRPException::GetErrorMessage()
{
return humanReadableError;
}
| 268
|
C++
|
.cpp
| 10
| 24.5
| 67
| 0.797665
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,137
|
weapons_dat.cpp
|
Wargus_stargus/src/kaitai/weapons_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "weapons_dat.h"
weapons_dat_t::weapons_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, weapons_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_label = 0;
m_graphics = 0;
m_explosion = 0;
m_target_flags = 0;
m_minimum_range = 0;
m_maximum_range = 0;
m_damage_upgrade = 0;
m_weapon_type = 0;
m_weapon_behaviour = 0;
m_remove_after = 0;
m_explosive_type = 0;
m_inner_splash_range = 0;
m_medium_splash_range = 0;
m_outer_splash_range = 0;
m_damage_amount = 0;
m_damage_bonus = 0;
m_weapon_cooldown = 0;
m_damage_factor = 0;
m_attack_angle = 0;
m_launch_spin = 0;
m_x_offset = 0;
m_y_offset = 0;
m_error_message = 0;
m_icon = 0;
f_num_lines = false;
f_record_size = false;
f_file_size = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void weapons_dat_t::_read() {
m_label = new std::vector<uint16_t>();
const int l_label = num_lines();
for (int i = 0; i < l_label; i++) {
m_label->push_back(m__io->read_u2le());
}
m_graphics = new std::vector<uint32_t>();
const int l_graphics = num_lines();
for (int i = 0; i < l_graphics; i++) {
m_graphics->push_back(m__io->read_u4le());
}
m_explosion = new std::vector<uint8_t>();
const int l_explosion = num_lines();
for (int i = 0; i < l_explosion; i++) {
m_explosion->push_back(m__io->read_u1());
}
m_target_flags = new std::vector<attack_type_enum_t>();
const int l_target_flags = num_lines();
for (int i = 0; i < l_target_flags; i++) {
m_target_flags->push_back(static_cast<weapons_dat_t::attack_type_enum_t>(m__io->read_u2le()));
}
m_minimum_range = new std::vector<uint32_t>();
const int l_minimum_range = num_lines();
for (int i = 0; i < l_minimum_range; i++) {
m_minimum_range->push_back(m__io->read_u4le());
}
m_maximum_range = new std::vector<uint32_t>();
const int l_maximum_range = num_lines();
for (int i = 0; i < l_maximum_range; i++) {
m_maximum_range->push_back(m__io->read_u4le());
}
m_damage_upgrade = new std::vector<uint8_t>();
const int l_damage_upgrade = num_lines();
for (int i = 0; i < l_damage_upgrade; i++) {
m_damage_upgrade->push_back(m__io->read_u1());
}
m_weapon_type = new std::vector<weapon_type_enum_t>();
const int l_weapon_type = num_lines();
for (int i = 0; i < l_weapon_type; i++) {
m_weapon_type->push_back(static_cast<weapons_dat_t::weapon_type_enum_t>(m__io->read_u1()));
}
m_weapon_behaviour = new std::vector<uint8_t>();
const int l_weapon_behaviour = num_lines();
for (int i = 0; i < l_weapon_behaviour; i++) {
m_weapon_behaviour->push_back(m__io->read_u1());
}
m_remove_after = new std::vector<uint8_t>();
const int l_remove_after = num_lines();
for (int i = 0; i < l_remove_after; i++) {
m_remove_after->push_back(m__io->read_u1());
}
m_explosive_type = new std::vector<uint8_t>();
const int l_explosive_type = num_lines();
for (int i = 0; i < l_explosive_type; i++) {
m_explosive_type->push_back(m__io->read_u1());
}
m_inner_splash_range = new std::vector<uint16_t>();
const int l_inner_splash_range = num_lines();
for (int i = 0; i < l_inner_splash_range; i++) {
m_inner_splash_range->push_back(m__io->read_u2le());
}
m_medium_splash_range = new std::vector<uint16_t>();
const int l_medium_splash_range = num_lines();
for (int i = 0; i < l_medium_splash_range; i++) {
m_medium_splash_range->push_back(m__io->read_u2le());
}
m_outer_splash_range = new std::vector<uint16_t>();
const int l_outer_splash_range = num_lines();
for (int i = 0; i < l_outer_splash_range; i++) {
m_outer_splash_range->push_back(m__io->read_u2le());
}
m_damage_amount = new std::vector<uint16_t>();
const int l_damage_amount = num_lines();
for (int i = 0; i < l_damage_amount; i++) {
m_damage_amount->push_back(m__io->read_u2le());
}
m_damage_bonus = new std::vector<uint16_t>();
const int l_damage_bonus = num_lines();
for (int i = 0; i < l_damage_bonus; i++) {
m_damage_bonus->push_back(m__io->read_u2le());
}
m_weapon_cooldown = new std::vector<uint8_t>();
const int l_weapon_cooldown = num_lines();
for (int i = 0; i < l_weapon_cooldown; i++) {
m_weapon_cooldown->push_back(m__io->read_u1());
}
m_damage_factor = new std::vector<uint8_t>();
const int l_damage_factor = num_lines();
for (int i = 0; i < l_damage_factor; i++) {
m_damage_factor->push_back(m__io->read_u1());
}
m_attack_angle = new std::vector<uint8_t>();
const int l_attack_angle = num_lines();
for (int i = 0; i < l_attack_angle; i++) {
m_attack_angle->push_back(m__io->read_u1());
}
m_launch_spin = new std::vector<uint8_t>();
const int l_launch_spin = num_lines();
for (int i = 0; i < l_launch_spin; i++) {
m_launch_spin->push_back(m__io->read_u1());
}
m_x_offset = new std::vector<uint8_t>();
const int l_x_offset = num_lines();
for (int i = 0; i < l_x_offset; i++) {
m_x_offset->push_back(m__io->read_u1());
}
m_y_offset = new std::vector<uint8_t>();
const int l_y_offset = num_lines();
for (int i = 0; i < l_y_offset; i++) {
m_y_offset->push_back(m__io->read_u1());
}
m_error_message = new std::vector<uint16_t>();
const int l_error_message = num_lines();
for (int i = 0; i < l_error_message; i++) {
m_error_message->push_back(m__io->read_u2le());
}
m_icon = new std::vector<uint16_t>();
const int l_icon = num_lines();
for (int i = 0; i < l_icon; i++) {
m_icon->push_back(m__io->read_u2le());
}
}
weapons_dat_t::~weapons_dat_t() {
_clean_up();
}
void weapons_dat_t::_clean_up() {
if (m_label) {
delete m_label; m_label = 0;
}
if (m_graphics) {
delete m_graphics; m_graphics = 0;
}
if (m_explosion) {
delete m_explosion; m_explosion = 0;
}
if (m_target_flags) {
delete m_target_flags; m_target_flags = 0;
}
if (m_minimum_range) {
delete m_minimum_range; m_minimum_range = 0;
}
if (m_maximum_range) {
delete m_maximum_range; m_maximum_range = 0;
}
if (m_damage_upgrade) {
delete m_damage_upgrade; m_damage_upgrade = 0;
}
if (m_weapon_type) {
delete m_weapon_type; m_weapon_type = 0;
}
if (m_weapon_behaviour) {
delete m_weapon_behaviour; m_weapon_behaviour = 0;
}
if (m_remove_after) {
delete m_remove_after; m_remove_after = 0;
}
if (m_explosive_type) {
delete m_explosive_type; m_explosive_type = 0;
}
if (m_inner_splash_range) {
delete m_inner_splash_range; m_inner_splash_range = 0;
}
if (m_medium_splash_range) {
delete m_medium_splash_range; m_medium_splash_range = 0;
}
if (m_outer_splash_range) {
delete m_outer_splash_range; m_outer_splash_range = 0;
}
if (m_damage_amount) {
delete m_damage_amount; m_damage_amount = 0;
}
if (m_damage_bonus) {
delete m_damage_bonus; m_damage_bonus = 0;
}
if (m_weapon_cooldown) {
delete m_weapon_cooldown; m_weapon_cooldown = 0;
}
if (m_damage_factor) {
delete m_damage_factor; m_damage_factor = 0;
}
if (m_attack_angle) {
delete m_attack_angle; m_attack_angle = 0;
}
if (m_launch_spin) {
delete m_launch_spin; m_launch_spin = 0;
}
if (m_x_offset) {
delete m_x_offset; m_x_offset = 0;
}
if (m_y_offset) {
delete m_y_offset; m_y_offset = 0;
}
if (m_error_message) {
delete m_error_message; m_error_message = 0;
}
if (m_icon) {
delete m_icon; m_icon = 0;
}
}
int32_t weapons_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = (file_size() / record_size());
f_num_lines = true;
return m_num_lines;
}
int8_t weapons_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 42;
f_record_size = true;
return m_record_size;
}
int32_t weapons_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
| 8,645
|
C++
|
.cpp
| 259
| 27.756757
| 131
| 0.574549
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,138
|
flingy_dat.cpp
|
Wargus_stargus/src/kaitai/flingy_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "flingy_dat.h"
flingy_dat_t::flingy_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, flingy_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_sprite = 0;
m_speed = 0;
m_acceleration = 0;
m_halt_distance = 0;
m_turn_radius = 0;
m_unused = 0;
m_movement_control = 0;
f_num_lines = false;
f_record_size = false;
f_file_size = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void flingy_dat_t::_read() {
m_sprite = new std::vector<uint16_t>();
const int l_sprite = num_lines();
for (int i = 0; i < l_sprite; i++) {
m_sprite->push_back(m__io->read_u2le());
}
m_speed = new std::vector<uint32_t>();
const int l_speed = num_lines();
for (int i = 0; i < l_speed; i++) {
m_speed->push_back(m__io->read_u4le());
}
m_acceleration = new std::vector<uint16_t>();
const int l_acceleration = num_lines();
for (int i = 0; i < l_acceleration; i++) {
m_acceleration->push_back(m__io->read_u2le());
}
m_halt_distance = new std::vector<uint32_t>();
const int l_halt_distance = num_lines();
for (int i = 0; i < l_halt_distance; i++) {
m_halt_distance->push_back(m__io->read_u4le());
}
m_turn_radius = new std::vector<uint8_t>();
const int l_turn_radius = num_lines();
for (int i = 0; i < l_turn_radius; i++) {
m_turn_radius->push_back(m__io->read_u1());
}
m_unused = new std::vector<uint8_t>();
const int l_unused = num_lines();
for (int i = 0; i < l_unused; i++) {
m_unused->push_back(m__io->read_u1());
}
m_movement_control = new std::vector<uint8_t>();
const int l_movement_control = num_lines();
for (int i = 0; i < l_movement_control; i++) {
m_movement_control->push_back(m__io->read_u1());
}
}
flingy_dat_t::~flingy_dat_t() {
_clean_up();
}
void flingy_dat_t::_clean_up() {
if (m_sprite) {
delete m_sprite; m_sprite = 0;
}
if (m_speed) {
delete m_speed; m_speed = 0;
}
if (m_acceleration) {
delete m_acceleration; m_acceleration = 0;
}
if (m_halt_distance) {
delete m_halt_distance; m_halt_distance = 0;
}
if (m_turn_radius) {
delete m_turn_radius; m_turn_radius = 0;
}
if (m_unused) {
delete m_unused; m_unused = 0;
}
if (m_movement_control) {
delete m_movement_control; m_movement_control = 0;
}
}
int32_t flingy_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = (file_size() / record_size());
f_num_lines = true;
return m_num_lines;
}
int8_t flingy_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 15;
f_record_size = true;
return m_record_size;
}
int32_t flingy_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
| 3,147
|
C++
|
.cpp
| 106
| 24.45283
| 128
| 0.57058
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,139
|
tileset_vf4.cpp
|
Wargus_stargus/src/kaitai/tileset_vf4.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "tileset_vf4.h"
tileset_vf4_t::tileset_vf4_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, tileset_vf4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_elements = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vf4_t::_read() {
m_elements = new std::vector<minitile_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_elements->push_back(new minitile_t(m__io, this, m__root));
i++;
}
}
}
tileset_vf4_t::~tileset_vf4_t() {
_clean_up();
}
void tileset_vf4_t::_clean_up() {
if (m_elements) {
for (std::vector<minitile_t*>::iterator it = m_elements->begin(); it != m_elements->end(); ++it) {
delete *it;
}
delete m_elements; m_elements = 0;
}
}
tileset_vf4_t::minitile_t::minitile_t(kaitai::kstream* p__io, tileset_vf4_t* p__parent, tileset_vf4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_flags = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vf4_t::minitile_t::_read() {
m_flags = new std::vector<minitile_flags_types_t*>();
const int l_flags = 16;
for (int i = 0; i < l_flags; i++) {
m_flags->push_back(new minitile_flags_types_t(m__io, this, m__root));
}
}
tileset_vf4_t::minitile_t::~minitile_t() {
_clean_up();
}
void tileset_vf4_t::minitile_t::_clean_up() {
if (m_flags) {
for (std::vector<minitile_flags_types_t*>::iterator it = m_flags->begin(); it != m_flags->end(); ++it) {
delete *it;
}
delete m_flags; m_flags = 0;
}
}
tileset_vf4_t::minitile_flags_types_t::minitile_flags_types_t(kaitai::kstream* p__io, tileset_vf4_t::minitile_t* p__parent, tileset_vf4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
f_walkable = false;
f_blocks_view = false;
f_mid_elevation = false;
f_ramp = false;
f_high_elevation = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vf4_t::minitile_flags_types_t::_read() {
m_flags_raw = m__io->read_u2le();
}
tileset_vf4_t::minitile_flags_types_t::~minitile_flags_types_t() {
_clean_up();
}
void tileset_vf4_t::minitile_flags_types_t::_clean_up() {
}
int32_t tileset_vf4_t::minitile_flags_types_t::walkable() {
if (f_walkable)
return m_walkable;
m_walkable = (flags_raw() & 1);
f_walkable = true;
return m_walkable;
}
int32_t tileset_vf4_t::minitile_flags_types_t::blocks_view() {
if (f_blocks_view)
return m_blocks_view;
m_blocks_view = (flags_raw() & 8);
f_blocks_view = true;
return m_blocks_view;
}
int32_t tileset_vf4_t::minitile_flags_types_t::mid_elevation() {
if (f_mid_elevation)
return m_mid_elevation;
m_mid_elevation = (flags_raw() & 2);
f_mid_elevation = true;
return m_mid_elevation;
}
int32_t tileset_vf4_t::minitile_flags_types_t::ramp() {
if (f_ramp)
return m_ramp;
m_ramp = (flags_raw() & 16);
f_ramp = true;
return m_ramp;
}
int32_t tileset_vf4_t::minitile_flags_types_t::high_elevation() {
if (f_high_elevation)
return m_high_elevation;
m_high_elevation = (flags_raw() & 4);
f_high_elevation = true;
return m_high_elevation;
}
| 3,553
|
C++
|
.cpp
| 121
| 24.322314
| 174
| 0.585459
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,140
|
portdata_dat.cpp
|
Wargus_stargus/src/kaitai/portdata_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "portdata_dat.h"
portdata_dat_t::portdata_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, portdata_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_video_idle = 0;
m_video_talking = 0;
m_change_idle = 0;
m_change_talking = 0;
m_unknown1_idle = 0;
m_unknown1_talking = 0;
f_num_lines = false;
f_record_size = false;
f_file_size = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void portdata_dat_t::_read() {
m_video_idle = new std::vector<uint32_t>();
const int l_video_idle = (num_lines() / 2);
for (int i = 0; i < l_video_idle; i++) {
m_video_idle->push_back(m__io->read_u4le());
}
m_video_talking = new std::vector<uint32_t>();
const int l_video_talking = (num_lines() / 2);
for (int i = 0; i < l_video_talking; i++) {
m_video_talking->push_back(m__io->read_u4le());
}
m_change_idle = new std::vector<uint8_t>();
const int l_change_idle = (num_lines() / 2);
for (int i = 0; i < l_change_idle; i++) {
m_change_idle->push_back(m__io->read_u1());
}
m_change_talking = new std::vector<uint8_t>();
const int l_change_talking = (num_lines() / 2);
for (int i = 0; i < l_change_talking; i++) {
m_change_talking->push_back(m__io->read_u1());
}
m_unknown1_idle = new std::vector<uint8_t>();
const int l_unknown1_idle = (num_lines() / 2);
for (int i = 0; i < l_unknown1_idle; i++) {
m_unknown1_idle->push_back(m__io->read_u1());
}
m_unknown1_talking = new std::vector<uint8_t>();
const int l_unknown1_talking = (num_lines() / 2);
for (int i = 0; i < l_unknown1_talking; i++) {
m_unknown1_talking->push_back(m__io->read_u1());
}
}
portdata_dat_t::~portdata_dat_t() {
_clean_up();
}
void portdata_dat_t::_clean_up() {
if (m_video_idle) {
delete m_video_idle; m_video_idle = 0;
}
if (m_video_talking) {
delete m_video_talking; m_video_talking = 0;
}
if (m_change_idle) {
delete m_change_idle; m_change_idle = 0;
}
if (m_change_talking) {
delete m_change_talking; m_change_talking = 0;
}
if (m_unknown1_idle) {
delete m_unknown1_idle; m_unknown1_idle = 0;
}
if (m_unknown1_talking) {
delete m_unknown1_talking; m_unknown1_talking = 0;
}
}
int32_t portdata_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = (file_size() / record_size());
f_num_lines = true;
return m_num_lines;
}
int8_t portdata_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 6;
f_record_size = true;
return m_record_size;
}
int32_t portdata_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
| 3,052
|
C++
|
.cpp
| 97
| 26.28866
| 134
| 0.581127
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,141
|
tileset_vr4.cpp
|
Wargus_stargus/src/kaitai/tileset_vr4.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "tileset_vr4.h"
tileset_vr4_t::tileset_vr4_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, tileset_vr4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_elements = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vr4_t::_read() {
m_elements = new std::vector<pixel_type_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_elements->push_back(new pixel_type_t(m__io, this, m__root));
i++;
}
}
}
tileset_vr4_t::~tileset_vr4_t() {
_clean_up();
}
void tileset_vr4_t::_clean_up() {
if (m_elements) {
for (std::vector<pixel_type_t*>::iterator it = m_elements->begin(); it != m_elements->end(); ++it) {
delete *it;
}
delete m_elements; m_elements = 0;
}
}
tileset_vr4_t::pixel_type_t::pixel_type_t(kaitai::kstream* p__io, tileset_vr4_t* p__parent, tileset_vr4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vr4_t::pixel_type_t::_read() {
m_minitile = m__io->read_bytes(64);
}
tileset_vr4_t::pixel_type_t::~pixel_type_t() {
_clean_up();
}
void tileset_vr4_t::pixel_type_t::_clean_up() {
}
| 1,464
|
C++
|
.cpp
| 52
| 22.942308
| 142
| 0.555318
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,142
|
iscript_bin.cpp
|
Wargus_stargus/src/kaitai/iscript_bin.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "iscript_bin.h"
iscript_bin_t::iscript_bin_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_entree_offsets = 0;
m_scpe = 0;
f_version_tag = false;
f_entree_table_pos = false;
f_entree_offsets = false;
f_scpe = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::_read() {
m_first_word = m__io->read_u2le();
}
iscript_bin_t::~iscript_bin_t() {
_clean_up();
}
void iscript_bin_t::_clean_up() {
if (f_version_tag) {
}
if (f_entree_offsets) {
if (m_entree_offsets) {
for (std::vector<entree_offset_type_t*>::iterator it = m_entree_offsets->begin(); it != m_entree_offsets->end(); ++it) {
delete *it;
}
delete m_entree_offsets; m_entree_offsets = 0;
}
}
if (f_scpe) {
if (m_scpe) {
for (std::vector<scpe_type_t*>::iterator it = m_scpe->begin(); it != m_scpe->end(); ++it) {
delete *it;
}
delete m_scpe; m_scpe = 0;
}
}
}
iscript_bin_t::scpe_content_type_t::scpe_content_type_t(kaitai::kstream* p__io, iscript_bin_t::scpe_type_t* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_scpe_opcode_list = 0;
f_scpe_opcode_list = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::scpe_content_type_t::_read() {
m_scpe_opcode_offset = m__io->read_u2le();
}
iscript_bin_t::scpe_content_type_t::~scpe_content_type_t() {
_clean_up();
}
void iscript_bin_t::scpe_content_type_t::_clean_up() {
if (f_scpe_opcode_list && !n_scpe_opcode_list) {
if (m_scpe_opcode_list) {
delete m_scpe_opcode_list; m_scpe_opcode_list = 0;
}
}
}
opcode_list_type_t* iscript_bin_t::scpe_content_type_t::scpe_opcode_list() {
if (f_scpe_opcode_list)
return m_scpe_opcode_list;
n_scpe_opcode_list = true;
if (scpe_opcode_offset() != 0) {
n_scpe_opcode_list = false;
std::streampos _pos = m__io->pos();
m__io->seek(scpe_opcode_offset());
m_scpe_opcode_list = new opcode_list_type_t(_parent(), _root(), m__io);
m__io->seek(_pos);
f_scpe_opcode_list = true;
}
return m_scpe_opcode_list;
}
iscript_bin_t::trgtrangecondjmp_type_t::trgtrangecondjmp_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::trgtrangecondjmp_type_t::_read() {
m_distance = m__io->read_u2le();
m_labelname = m__io->read_u2le();
}
iscript_bin_t::trgtrangecondjmp_type_t::~trgtrangecondjmp_type_t() {
_clean_up();
}
void iscript_bin_t::trgtrangecondjmp_type_t::_clean_up() {
}
iscript_bin_t::u1_type_t::u1_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::u1_type_t::_read() {
m_value = m__io->read_u1();
}
iscript_bin_t::u1_type_t::~u1_type_t() {
_clean_up();
}
void iscript_bin_t::u1_type_t::_clean_up() {
}
iscript_bin_t::playsounds_type_t::playsounds_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_sound = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::playsounds_type_t::_read() {
m_number_sounds = m__io->read_u1();
m_sound = new std::vector<uint16_t>();
const int l_sound = number_sounds();
for (int i = 0; i < l_sound; i++) {
m_sound->push_back(m__io->read_u2le());
}
}
iscript_bin_t::playsounds_type_t::~playsounds_type_t() {
_clean_up();
}
void iscript_bin_t::playsounds_type_t::_clean_up() {
if (m_sound) {
delete m_sound; m_sound = 0;
}
}
iscript_bin_t::randcondjmp_type_t::randcondjmp_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::randcondjmp_type_t::_read() {
m_randchance = m__io->read_u1();
m_labelname = m__io->read_u2le();
}
iscript_bin_t::randcondjmp_type_t::~randcondjmp_type_t() {
_clean_up();
}
void iscript_bin_t::randcondjmp_type_t::_clean_up() {
}
iscript_bin_t::empty_type_t::empty_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::empty_type_t::_read() {
}
iscript_bin_t::empty_type_t::~empty_type_t() {
_clean_up();
}
void iscript_bin_t::empty_type_t::_clean_up() {
}
iscript_bin_t::pos_type_t::pos_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::pos_type_t::_read() {
m_x = m__io->read_u1();
m_y = m__io->read_u1();
}
iscript_bin_t::pos_type_t::~pos_type_t() {
_clean_up();
}
void iscript_bin_t::pos_type_t::_clean_up() {
}
iscript_bin_t::sprl_type_t::sprl_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_pos = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::sprl_type_t::_read() {
m_sprite = m__io->read_u2le();
m_pos = new pos_type_t(m__io, this, m__root);
}
iscript_bin_t::sprl_type_t::~sprl_type_t() {
_clean_up();
}
void iscript_bin_t::sprl_type_t::_clean_up() {
if (m_pos) {
delete m_pos; m_pos = 0;
}
}
iscript_bin_t::opcode_type_t::opcode_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::opcode_type_t::_read() {
m_code = static_cast<iscript_bin_t::opcode_t>(m__io->read_u1());
switch (code()) {
case iscript_bin_t::OPCODE_TURN1CWISE: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IMGOLORIG: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_3E: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SIGORDER: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ENGFRAME: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TURNCCWISE: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_2D: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_END: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_PLAYFRAM: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TMPRMGRAPHICSTART: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IMGULNEXTID: {
m_args = new pos_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_PLAYSNDBTWN: {
m_args = new playsndbtwn_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_0C: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ENGSET: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SWITCHUL: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TRGTARCCONDJMP: {
m_args = new trgcondjmp_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETFLIPSTATE: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETPOS: {
m_args = new pos_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IMGOLUSELO: {
m_args = new imgl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_LOWSPRUL: {
m_args = new sprl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TURNRAND: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_DOMISSILEDMG: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_HIGHSPROL: {
m_args = new sprl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETFLSPEED: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_USEWEAPON: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_WARPOVERLAY: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_GOTOREPEATATTK: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_UFLUNSTABLE: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ORDERDONE: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TRGTRANGECONDJMP: {
m_args = new trgtrangecondjmp_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_RETURN: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_CASTSPELL: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_FOLLOWMAINGRAPHIC: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_RANDCONDJMP: {
m_args = new randcondjmp_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_NOBRKCODEEND: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_CALL: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_NOBRKCODESTART: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_WAIT: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SPROL: {
m_args = new sprl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TMPRMGRAPHICEND: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_CREATEGASOVERLAYS: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETFLDIRECT: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_PWRUPCONDJMP: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETHORPOS: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SPRULUSELO: {
m_args = new sprl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SPRUL: {
m_args = new sprl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_GRDSPROL: {
m_args = new sprl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_MOVE: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_GOTO: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IMGUL: {
m_args = new imgl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_PLAYFRAMTILE: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ATTKSHIFTPROJ: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_LIFTOFFCONDJMP: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IMGOL: {
m_args = new imgl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IMGULUSELO: {
m_args = new imgl_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ATTACK: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ATTACKMELEE: {
m_args = new playsounds_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SPROLUSELO: {
m_args = new sprov_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_PLAYSNDRAND: {
m_args = new playsounds_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_IGNOREREST: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_PLAYSND: {
m_args = new u2_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_UNKNOWN_43: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETVERTPOS: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_DOGRDDAMAGE: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_WAITRAND: {
m_args = new waitrand_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_TURNCWISE: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_CURDIRECTCONDJMP: {
m_args = new trgcondjmp_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_SETSPAWNFRAME: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
case iscript_bin_t::OPCODE_ATTACKWITH: {
m_args = new u1_type_t(m__io, this, m__root);
break;
}
default: {
m_args = new empty_type_t(m__io, this, m__root);
break;
}
}
}
iscript_bin_t::opcode_type_t::~opcode_type_t() {
_clean_up();
}
void iscript_bin_t::opcode_type_t::_clean_up() {
if (m_args) {
delete m_args; m_args = 0;
}
}
iscript_bin_t::trgcondjmp_type_t::trgcondjmp_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::trgcondjmp_type_t::_read() {
m_angle1 = m__io->read_u2le();
m_angle2 = m__io->read_u2le();
m_labelname = m__io->read_u2le();
}
iscript_bin_t::trgcondjmp_type_t::~trgcondjmp_type_t() {
_clean_up();
}
void iscript_bin_t::trgcondjmp_type_t::_clean_up() {
}
iscript_bin_t::entree_offset_type_t::entree_offset_type_t(kaitai::kstream* p__io, iscript_bin_t* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::entree_offset_type_t::_read() {
m_iscript_id = m__io->read_u2le();
m_offset = m__io->read_u2le();
}
iscript_bin_t::entree_offset_type_t::~entree_offset_type_t() {
_clean_up();
}
void iscript_bin_t::entree_offset_type_t::_clean_up() {
}
iscript_bin_t::scpe_type_t::scpe_type_t(uint16_t p_i, kaitai::kstream* p__io, iscript_bin_t* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_i = p_i;
m_scpe_header = 0;
m_scpe_content = 0;
f_scpe_header = false;
f_num_scpe_content = false;
f_scpe_content = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::scpe_type_t::_read() {
}
iscript_bin_t::scpe_type_t::~scpe_type_t() {
_clean_up();
}
void iscript_bin_t::scpe_type_t::_clean_up() {
if (f_scpe_header) {
if (m_scpe_header) {
delete m_scpe_header; m_scpe_header = 0;
}
}
if (f_scpe_content) {
if (m_scpe_content) {
for (std::vector<scpe_content_type_t*>::iterator it = m_scpe_content->begin(); it != m_scpe_content->end(); ++it) {
delete *it;
}
delete m_scpe_content; m_scpe_content = 0;
}
}
}
iscript_bin_t::scpe_header_type_t* iscript_bin_t::scpe_type_t::scpe_header() {
if (f_scpe_header)
return m_scpe_header;
std::streampos _pos = m__io->pos();
m__io->seek(_parent()->entree_offsets()->at(i())->offset());
m_scpe_header = new scpe_header_type_t(m__io, this, m__root);
m__io->seek(_pos);
f_scpe_header = true;
return m_scpe_header;
}
int8_t iscript_bin_t::scpe_type_t::num_scpe_content() {
if (f_num_scpe_content)
return m_num_scpe_content;
m_num_scpe_content = ((scpe_header()->scpe_content_type() == 0) ? (2) : (((scpe_header()->scpe_content_type() == 1) ? (2) : (((scpe_header()->scpe_content_type() == 2) ? (4) : (((scpe_header()->scpe_content_type() == 12) ? (14) : (((scpe_header()->scpe_content_type() == 13) ? (14) : (((scpe_header()->scpe_content_type() == 14) ? (15) : (((scpe_header()->scpe_content_type() == 15) ? (15) : (((scpe_header()->scpe_content_type() == 20) ? (21) : (((scpe_header()->scpe_content_type() == 21) ? (21) : (((scpe_header()->scpe_content_type() == 23) ? (23) : (((scpe_header()->scpe_content_type() == 24) ? (25) : (((scpe_header()->scpe_content_type() == 26) ? (27) : (((scpe_header()->scpe_content_type() == 27) ? (27) : (((scpe_header()->scpe_content_type() == 28) ? (27) : (((scpe_header()->scpe_content_type() == 29) ? (27) : (0))))))))))))))))))))))))))))));
f_num_scpe_content = true;
return m_num_scpe_content;
}
std::vector<iscript_bin_t::scpe_content_type_t*>* iscript_bin_t::scpe_type_t::scpe_content() {
if (f_scpe_content)
return m_scpe_content;
std::streampos _pos = m__io->pos();
m__io->seek((_parent()->entree_offsets()->at(i())->offset() + 8));
m_scpe_content = new std::vector<scpe_content_type_t*>();
const int l_scpe_content = num_scpe_content();
for (int i = 0; i < l_scpe_content; i++) {
m_scpe_content->push_back(new scpe_content_type_t(m__io, this, m__root));
}
m__io->seek(_pos);
f_scpe_content = true;
return m_scpe_content;
}
iscript_bin_t::playsndbtwn_type_t::playsndbtwn_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::playsndbtwn_type_t::_read() {
m_firstsound = m__io->read_u2le();
m_lastsound = m__io->read_u2le();
}
iscript_bin_t::playsndbtwn_type_t::~playsndbtwn_type_t() {
_clean_up();
}
void iscript_bin_t::playsndbtwn_type_t::_clean_up() {
}
iscript_bin_t::imgl_type_t::imgl_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_pos = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::imgl_type_t::_read() {
m_image = m__io->read_u2le();
m_pos = new pos_type_t(m__io, this, m__root);
}
iscript_bin_t::imgl_type_t::~imgl_type_t() {
_clean_up();
}
void iscript_bin_t::imgl_type_t::_clean_up() {
if (m_pos) {
delete m_pos; m_pos = 0;
}
}
iscript_bin_t::waitrand_type_t::waitrand_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::waitrand_type_t::_read() {
m_ticks1 = m__io->read_u1();
m_ticks2 = m__io->read_u1();
}
iscript_bin_t::waitrand_type_t::~waitrand_type_t() {
_clean_up();
}
void iscript_bin_t::waitrand_type_t::_clean_up() {
}
iscript_bin_t::sprov_type_t::sprov_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::sprov_type_t::_read() {
m_sprite = m__io->read_u2le();
m_overlay = m__io->read_u1();
}
iscript_bin_t::sprov_type_t::~sprov_type_t() {
_clean_up();
}
void iscript_bin_t::sprov_type_t::_clean_up() {
}
iscript_bin_t::scpe_header_type_t::scpe_header_type_t(kaitai::kstream* p__io, iscript_bin_t::scpe_type_t* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::scpe_header_type_t::_read() {
m_scpe_magic = m__io->read_u4le();
m_scpe_content_type = m__io->read_u1();
m_padding = m__io->read_bytes(3);
}
iscript_bin_t::scpe_header_type_t::~scpe_header_type_t() {
_clean_up();
}
void iscript_bin_t::scpe_header_type_t::_clean_up() {
}
iscript_bin_t::u2_type_t::u2_type_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, iscript_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void iscript_bin_t::u2_type_t::_read() {
m_value = m__io->read_u2le();
}
iscript_bin_t::u2_type_t::~u2_type_t() {
_clean_up();
}
void iscript_bin_t::u2_type_t::_clean_up() {
}
uint32_t iscript_bin_t::version_tag() {
if (f_version_tag)
return m_version_tag;
std::streampos _pos = m__io->pos();
m__io->seek(2);
m_version_tag = m__io->read_u4le();
m__io->seek(_pos);
f_version_tag = true;
return m_version_tag;
}
uint16_t iscript_bin_t::entree_table_pos() {
if (f_entree_table_pos)
return m_entree_table_pos;
m_entree_table_pos = ((version_tag() == 0) ? (first_word()) : (0));
f_entree_table_pos = true;
return m_entree_table_pos;
}
std::vector<iscript_bin_t::entree_offset_type_t*>* iscript_bin_t::entree_offsets() {
if (f_entree_offsets)
return m_entree_offsets;
std::streampos _pos = m__io->pos();
m__io->seek(entree_table_pos());
m_entree_offsets = new std::vector<entree_offset_type_t*>();
{
int i = 0;
entree_offset_type_t* _;
do {
_ = new entree_offset_type_t(m__io, this, m__root);
m_entree_offsets->push_back(_);
i++;
} while (!(((_->iscript_id() == 65535) ? (_->offset() == 0) : (false))));
}
m__io->seek(_pos);
f_entree_offsets = true;
return m_entree_offsets;
}
std::vector<iscript_bin_t::scpe_type_t*>* iscript_bin_t::scpe() {
if (f_scpe)
return m_scpe;
m_scpe = new std::vector<scpe_type_t*>();
const int l_scpe = _root()->entree_offsets()->size();
for (int i = 0; i < l_scpe; i++) {
m_scpe->push_back(new scpe_type_t(i, m__io, this, m__root));
}
f_scpe = true;
return m_scpe;
}
| 24,707
|
C++
|
.cpp
| 799
| 25.296621
| 861
| 0.56125
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,143
|
units_dat.cpp
|
Wargus_stargus/src/kaitai/units_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "units_dat.h"
units_dat_t::units_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_flingy = 0;
m_subunit1 = 0;
m_subunit2 = 0;
m_infestation = 0;
m_construction_animation = 0;
m_unit_direction = 0;
m_shield_enable = 0;
m_shield_amount = 0;
m_hit_points = 0;
m_elevation_level = 0;
m_unknown = 0;
m_rank = 0;
m_ai_computer_idle = 0;
m_ai_human_idle = 0;
m_ai_return_to_idle = 0;
m_ai_attack_unit = 0;
m_ai_attack_move = 0;
m_ground_weapon = 0;
m_max_ground_hits = 0;
m_air_weapon = 0;
m_max_air_hits = 0;
m_ai_internal = 0;
m_special_ability_flags = 0;
m__raw_special_ability_flags = 0;
m__io__raw_special_ability_flags = 0;
m_target_acquisition_range = 0;
m_sight_range = 0;
m_armor_upgrade = 0;
m_unit_size = 0;
m_armor = 0;
m_right_click_action = 0;
m_ready_sound = 0;
m_what_sound_start = 0;
m_what_sound_end = 0;
m_piss_sound_start = 0;
m_piss_sound_end = 0;
m_yes_sound_start = 0;
m_yes_sound_end = 0;
m_staredit_placement_box = 0;
m_addon_position = 0;
m_unit_dimension = 0;
m_portrait = 0;
m_mineral_cost = 0;
m_vespene_cost = 0;
m_build_time = 0;
m_requirements = 0;
m_staredit_group_flags = 0;
m__raw_staredit_group_flags = 0;
m__io__raw_staredit_group_flags = 0;
m_supply_provided = 0;
m_supply_required = 0;
m_space_required = 0;
m_space_provided = 0;
m_build_score = 0;
m_destroy_score = 0;
m_unit_map_string = 0;
m_broodwar_flag = 0;
m_staredit_availability_flags = 0;
m__raw_staredit_availability_flags = 0;
m__io__raw_staredit_availability_flags = 0;
f_sc_file_size = false;
f_bw_file_size = false;
f_file_size = false;
f_is_format_sc = false;
f_is_format_bw = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::_read() {
m_flingy = new std::vector<uint8_t>();
const int l_flingy = 228;
for (int i = 0; i < l_flingy; i++) {
m_flingy->push_back(m__io->read_u1());
}
m_subunit1 = new std::vector<uint16_t>();
const int l_subunit1 = 228;
for (int i = 0; i < l_subunit1; i++) {
m_subunit1->push_back(m__io->read_u2le());
}
m_subunit2 = new std::vector<uint16_t>();
const int l_subunit2 = 228;
for (int i = 0; i < l_subunit2; i++) {
m_subunit2->push_back(m__io->read_u2le());
}
m_infestation = new std::vector<uint16_t>();
const int l_infestation = 96;
for (int i = 0; i < l_infestation; i++) {
m_infestation->push_back(m__io->read_u2le());
}
m_construction_animation = new std::vector<uint32_t>();
const int l_construction_animation = 228;
for (int i = 0; i < l_construction_animation; i++) {
m_construction_animation->push_back(m__io->read_u4le());
}
m_unit_direction = new std::vector<uint8_t>();
const int l_unit_direction = 228;
for (int i = 0; i < l_unit_direction; i++) {
m_unit_direction->push_back(m__io->read_u1());
}
m_shield_enable = new std::vector<uint8_t>();
const int l_shield_enable = 228;
for (int i = 0; i < l_shield_enable; i++) {
m_shield_enable->push_back(m__io->read_u1());
}
m_shield_amount = new std::vector<uint16_t>();
const int l_shield_amount = 228;
for (int i = 0; i < l_shield_amount; i++) {
m_shield_amount->push_back(m__io->read_u2le());
}
m_hit_points = new std::vector<hit_points_type_t*>();
const int l_hit_points = 228;
for (int i = 0; i < l_hit_points; i++) {
m_hit_points->push_back(new hit_points_type_t(m__io, this, m__root));
}
m_elevation_level = new std::vector<uint8_t>();
const int l_elevation_level = 228;
for (int i = 0; i < l_elevation_level; i++) {
m_elevation_level->push_back(m__io->read_u1());
}
m_unknown = new std::vector<uint8_t>();
const int l_unknown = 228;
for (int i = 0; i < l_unknown; i++) {
m_unknown->push_back(m__io->read_u1());
}
m_rank = new std::vector<uint8_t>();
const int l_rank = 228;
for (int i = 0; i < l_rank; i++) {
m_rank->push_back(m__io->read_u1());
}
m_ai_computer_idle = new std::vector<uint8_t>();
const int l_ai_computer_idle = 228;
for (int i = 0; i < l_ai_computer_idle; i++) {
m_ai_computer_idle->push_back(m__io->read_u1());
}
m_ai_human_idle = new std::vector<uint8_t>();
const int l_ai_human_idle = 228;
for (int i = 0; i < l_ai_human_idle; i++) {
m_ai_human_idle->push_back(m__io->read_u1());
}
m_ai_return_to_idle = new std::vector<uint8_t>();
const int l_ai_return_to_idle = 228;
for (int i = 0; i < l_ai_return_to_idle; i++) {
m_ai_return_to_idle->push_back(m__io->read_u1());
}
m_ai_attack_unit = new std::vector<uint8_t>();
const int l_ai_attack_unit = 228;
for (int i = 0; i < l_ai_attack_unit; i++) {
m_ai_attack_unit->push_back(m__io->read_u1());
}
m_ai_attack_move = new std::vector<uint8_t>();
const int l_ai_attack_move = 228;
for (int i = 0; i < l_ai_attack_move; i++) {
m_ai_attack_move->push_back(m__io->read_u1());
}
m_ground_weapon = new std::vector<uint8_t>();
const int l_ground_weapon = 228;
for (int i = 0; i < l_ground_weapon; i++) {
m_ground_weapon->push_back(m__io->read_u1());
}
n_max_ground_hits = true;
if (is_format_bw() == true) {
n_max_ground_hits = false;
m_max_ground_hits = new std::vector<uint8_t>();
const int l_max_ground_hits = 228;
for (int i = 0; i < l_max_ground_hits; i++) {
m_max_ground_hits->push_back(m__io->read_u1());
}
}
m_air_weapon = new std::vector<uint8_t>();
const int l_air_weapon = 228;
for (int i = 0; i < l_air_weapon; i++) {
m_air_weapon->push_back(m__io->read_u1());
}
n_max_air_hits = true;
if (is_format_bw() == true) {
n_max_air_hits = false;
m_max_air_hits = new std::vector<uint8_t>();
const int l_max_air_hits = 228;
for (int i = 0; i < l_max_air_hits; i++) {
m_max_air_hits->push_back(m__io->read_u1());
}
}
m_ai_internal = new std::vector<uint8_t>();
const int l_ai_internal = 228;
for (int i = 0; i < l_ai_internal; i++) {
m_ai_internal->push_back(m__io->read_u1());
}
m__raw_special_ability_flags = new std::vector<std::string>();
m__io__raw_special_ability_flags = new std::vector<kaitai::kstream*>();
m_special_ability_flags = new std::vector<special_ability_flags_type_t*>();
const int l_special_ability_flags = 228;
for (int i = 0; i < l_special_ability_flags; i++) {
m__raw_special_ability_flags->push_back(m__io->read_bytes(4));
kaitai::kstream* io__raw_special_ability_flags = new kaitai::kstream(m__raw_special_ability_flags->at(m__raw_special_ability_flags->size() - 1));
m__io__raw_special_ability_flags->push_back(io__raw_special_ability_flags);
m_special_ability_flags->push_back(new special_ability_flags_type_t(io__raw_special_ability_flags, this, m__root));
}
m_target_acquisition_range = new std::vector<uint8_t>();
const int l_target_acquisition_range = 228;
for (int i = 0; i < l_target_acquisition_range; i++) {
m_target_acquisition_range->push_back(m__io->read_u1());
}
m_sight_range = new std::vector<uint8_t>();
const int l_sight_range = 228;
for (int i = 0; i < l_sight_range; i++) {
m_sight_range->push_back(m__io->read_u1());
}
m_armor_upgrade = new std::vector<uint8_t>();
const int l_armor_upgrade = 228;
for (int i = 0; i < l_armor_upgrade; i++) {
m_armor_upgrade->push_back(m__io->read_u1());
}
m_unit_size = new std::vector<unit_size_enum_t>();
const int l_unit_size = 228;
for (int i = 0; i < l_unit_size; i++) {
m_unit_size->push_back(static_cast<units_dat_t::unit_size_enum_t>(m__io->read_u1()));
}
m_armor = new std::vector<uint8_t>();
const int l_armor = 228;
for (int i = 0; i < l_armor; i++) {
m_armor->push_back(m__io->read_u1());
}
m_right_click_action = new std::vector<right_click_action_enum_t>();
const int l_right_click_action = 228;
for (int i = 0; i < l_right_click_action; i++) {
m_right_click_action->push_back(static_cast<units_dat_t::right_click_action_enum_t>(m__io->read_u1()));
}
m_ready_sound = new std::vector<uint16_t>();
const int l_ready_sound = 106;
for (int i = 0; i < l_ready_sound; i++) {
m_ready_sound->push_back(m__io->read_u2le());
}
m_what_sound_start = new std::vector<uint16_t>();
const int l_what_sound_start = 228;
for (int i = 0; i < l_what_sound_start; i++) {
m_what_sound_start->push_back(m__io->read_u2le());
}
m_what_sound_end = new std::vector<uint16_t>();
const int l_what_sound_end = 228;
for (int i = 0; i < l_what_sound_end; i++) {
m_what_sound_end->push_back(m__io->read_u2le());
}
m_piss_sound_start = new std::vector<uint16_t>();
const int l_piss_sound_start = 106;
for (int i = 0; i < l_piss_sound_start; i++) {
m_piss_sound_start->push_back(m__io->read_u2le());
}
m_piss_sound_end = new std::vector<uint16_t>();
const int l_piss_sound_end = 106;
for (int i = 0; i < l_piss_sound_end; i++) {
m_piss_sound_end->push_back(m__io->read_u2le());
}
m_yes_sound_start = new std::vector<uint16_t>();
const int l_yes_sound_start = 106;
for (int i = 0; i < l_yes_sound_start; i++) {
m_yes_sound_start->push_back(m__io->read_u2le());
}
m_yes_sound_end = new std::vector<uint16_t>();
const int l_yes_sound_end = 106;
for (int i = 0; i < l_yes_sound_end; i++) {
m_yes_sound_end->push_back(m__io->read_u2le());
}
m_staredit_placement_box = new std::vector<staredit_placement_box_type_t*>();
const int l_staredit_placement_box = 228;
for (int i = 0; i < l_staredit_placement_box; i++) {
m_staredit_placement_box->push_back(new staredit_placement_box_type_t(m__io, this, m__root));
}
m_addon_position = new std::vector<addon_position_type_t*>();
const int l_addon_position = 96;
for (int i = 0; i < l_addon_position; i++) {
m_addon_position->push_back(new addon_position_type_t(m__io, this, m__root));
}
m_unit_dimension = new std::vector<unit_dimension_type_t*>();
const int l_unit_dimension = 228;
for (int i = 0; i < l_unit_dimension; i++) {
m_unit_dimension->push_back(new unit_dimension_type_t(m__io, this, m__root));
}
m_portrait = new std::vector<uint16_t>();
const int l_portrait = 228;
for (int i = 0; i < l_portrait; i++) {
m_portrait->push_back(m__io->read_u2le());
}
m_mineral_cost = new std::vector<uint16_t>();
const int l_mineral_cost = 228;
for (int i = 0; i < l_mineral_cost; i++) {
m_mineral_cost->push_back(m__io->read_u2le());
}
m_vespene_cost = new std::vector<uint16_t>();
const int l_vespene_cost = 228;
for (int i = 0; i < l_vespene_cost; i++) {
m_vespene_cost->push_back(m__io->read_u2le());
}
m_build_time = new std::vector<uint16_t>();
const int l_build_time = 228;
for (int i = 0; i < l_build_time; i++) {
m_build_time->push_back(m__io->read_u2le());
}
m_requirements = new std::vector<uint16_t>();
const int l_requirements = 228;
for (int i = 0; i < l_requirements; i++) {
m_requirements->push_back(m__io->read_u2le());
}
m__raw_staredit_group_flags = new std::vector<std::string>();
m__io__raw_staredit_group_flags = new std::vector<kaitai::kstream*>();
m_staredit_group_flags = new std::vector<staredit_group_flags_type_t*>();
const int l_staredit_group_flags = 228;
for (int i = 0; i < l_staredit_group_flags; i++) {
m__raw_staredit_group_flags->push_back(m__io->read_bytes(1));
kaitai::kstream* io__raw_staredit_group_flags = new kaitai::kstream(m__raw_staredit_group_flags->at(m__raw_staredit_group_flags->size() - 1));
m__io__raw_staredit_group_flags->push_back(io__raw_staredit_group_flags);
m_staredit_group_flags->push_back(new staredit_group_flags_type_t(io__raw_staredit_group_flags, this, m__root));
}
m_supply_provided = new std::vector<uint8_t>();
const int l_supply_provided = 228;
for (int i = 0; i < l_supply_provided; i++) {
m_supply_provided->push_back(m__io->read_u1());
}
m_supply_required = new std::vector<uint8_t>();
const int l_supply_required = 228;
for (int i = 0; i < l_supply_required; i++) {
m_supply_required->push_back(m__io->read_u1());
}
m_space_required = new std::vector<uint8_t>();
const int l_space_required = 228;
for (int i = 0; i < l_space_required; i++) {
m_space_required->push_back(m__io->read_u1());
}
m_space_provided = new std::vector<uint8_t>();
const int l_space_provided = 228;
for (int i = 0; i < l_space_provided; i++) {
m_space_provided->push_back(m__io->read_u1());
}
m_build_score = new std::vector<uint16_t>();
const int l_build_score = 228;
for (int i = 0; i < l_build_score; i++) {
m_build_score->push_back(m__io->read_u2le());
}
m_destroy_score = new std::vector<uint16_t>();
const int l_destroy_score = 228;
for (int i = 0; i < l_destroy_score; i++) {
m_destroy_score->push_back(m__io->read_u2le());
}
m_unit_map_string = new std::vector<uint16_t>();
const int l_unit_map_string = 228;
for (int i = 0; i < l_unit_map_string; i++) {
m_unit_map_string->push_back(m__io->read_u2le());
}
n_broodwar_flag = true;
if (is_format_bw() == true) {
n_broodwar_flag = false;
m_broodwar_flag = new std::vector<uint8_t>();
const int l_broodwar_flag = 228;
for (int i = 0; i < l_broodwar_flag; i++) {
m_broodwar_flag->push_back(m__io->read_u1());
}
}
m__raw_staredit_availability_flags = new std::vector<std::string>();
m__io__raw_staredit_availability_flags = new std::vector<kaitai::kstream*>();
m_staredit_availability_flags = new std::vector<staredit_availability_flags_type_t*>();
const int l_staredit_availability_flags = 228;
for (int i = 0; i < l_staredit_availability_flags; i++) {
m__raw_staredit_availability_flags->push_back(m__io->read_bytes(2));
kaitai::kstream* io__raw_staredit_availability_flags = new kaitai::kstream(m__raw_staredit_availability_flags->at(m__raw_staredit_availability_flags->size() - 1));
m__io__raw_staredit_availability_flags->push_back(io__raw_staredit_availability_flags);
m_staredit_availability_flags->push_back(new staredit_availability_flags_type_t(io__raw_staredit_availability_flags, this, m__root));
}
}
units_dat_t::~units_dat_t() {
_clean_up();
}
void units_dat_t::_clean_up() {
if (m_flingy) {
delete m_flingy; m_flingy = 0;
}
if (m_subunit1) {
delete m_subunit1; m_subunit1 = 0;
}
if (m_subunit2) {
delete m_subunit2; m_subunit2 = 0;
}
if (m_infestation) {
delete m_infestation; m_infestation = 0;
}
if (m_construction_animation) {
delete m_construction_animation; m_construction_animation = 0;
}
if (m_unit_direction) {
delete m_unit_direction; m_unit_direction = 0;
}
if (m_shield_enable) {
delete m_shield_enable; m_shield_enable = 0;
}
if (m_shield_amount) {
delete m_shield_amount; m_shield_amount = 0;
}
if (m_hit_points) {
for (std::vector<hit_points_type_t*>::iterator it = m_hit_points->begin(); it != m_hit_points->end(); ++it) {
delete *it;
}
delete m_hit_points; m_hit_points = 0;
}
if (m_elevation_level) {
delete m_elevation_level; m_elevation_level = 0;
}
if (m_unknown) {
delete m_unknown; m_unknown = 0;
}
if (m_rank) {
delete m_rank; m_rank = 0;
}
if (m_ai_computer_idle) {
delete m_ai_computer_idle; m_ai_computer_idle = 0;
}
if (m_ai_human_idle) {
delete m_ai_human_idle; m_ai_human_idle = 0;
}
if (m_ai_return_to_idle) {
delete m_ai_return_to_idle; m_ai_return_to_idle = 0;
}
if (m_ai_attack_unit) {
delete m_ai_attack_unit; m_ai_attack_unit = 0;
}
if (m_ai_attack_move) {
delete m_ai_attack_move; m_ai_attack_move = 0;
}
if (m_ground_weapon) {
delete m_ground_weapon; m_ground_weapon = 0;
}
if (!n_max_ground_hits) {
if (m_max_ground_hits) {
delete m_max_ground_hits; m_max_ground_hits = 0;
}
}
if (m_air_weapon) {
delete m_air_weapon; m_air_weapon = 0;
}
if (!n_max_air_hits) {
if (m_max_air_hits) {
delete m_max_air_hits; m_max_air_hits = 0;
}
}
if (m_ai_internal) {
delete m_ai_internal; m_ai_internal = 0;
}
if (m__raw_special_ability_flags) {
delete m__raw_special_ability_flags; m__raw_special_ability_flags = 0;
}
if (m__io__raw_special_ability_flags) {
for (std::vector<kaitai::kstream*>::iterator it = m__io__raw_special_ability_flags->begin(); it != m__io__raw_special_ability_flags->end(); ++it) {
delete *it;
}
delete m__io__raw_special_ability_flags; m__io__raw_special_ability_flags = 0;
}
if (m_special_ability_flags) {
for (std::vector<special_ability_flags_type_t*>::iterator it = m_special_ability_flags->begin(); it != m_special_ability_flags->end(); ++it) {
delete *it;
}
delete m_special_ability_flags; m_special_ability_flags = 0;
}
if (m_target_acquisition_range) {
delete m_target_acquisition_range; m_target_acquisition_range = 0;
}
if (m_sight_range) {
delete m_sight_range; m_sight_range = 0;
}
if (m_armor_upgrade) {
delete m_armor_upgrade; m_armor_upgrade = 0;
}
if (m_unit_size) {
delete m_unit_size; m_unit_size = 0;
}
if (m_armor) {
delete m_armor; m_armor = 0;
}
if (m_right_click_action) {
delete m_right_click_action; m_right_click_action = 0;
}
if (m_ready_sound) {
delete m_ready_sound; m_ready_sound = 0;
}
if (m_what_sound_start) {
delete m_what_sound_start; m_what_sound_start = 0;
}
if (m_what_sound_end) {
delete m_what_sound_end; m_what_sound_end = 0;
}
if (m_piss_sound_start) {
delete m_piss_sound_start; m_piss_sound_start = 0;
}
if (m_piss_sound_end) {
delete m_piss_sound_end; m_piss_sound_end = 0;
}
if (m_yes_sound_start) {
delete m_yes_sound_start; m_yes_sound_start = 0;
}
if (m_yes_sound_end) {
delete m_yes_sound_end; m_yes_sound_end = 0;
}
if (m_staredit_placement_box) {
for (std::vector<staredit_placement_box_type_t*>::iterator it = m_staredit_placement_box->begin(); it != m_staredit_placement_box->end(); ++it) {
delete *it;
}
delete m_staredit_placement_box; m_staredit_placement_box = 0;
}
if (m_addon_position) {
for (std::vector<addon_position_type_t*>::iterator it = m_addon_position->begin(); it != m_addon_position->end(); ++it) {
delete *it;
}
delete m_addon_position; m_addon_position = 0;
}
if (m_unit_dimension) {
for (std::vector<unit_dimension_type_t*>::iterator it = m_unit_dimension->begin(); it != m_unit_dimension->end(); ++it) {
delete *it;
}
delete m_unit_dimension; m_unit_dimension = 0;
}
if (m_portrait) {
delete m_portrait; m_portrait = 0;
}
if (m_mineral_cost) {
delete m_mineral_cost; m_mineral_cost = 0;
}
if (m_vespene_cost) {
delete m_vespene_cost; m_vespene_cost = 0;
}
if (m_build_time) {
delete m_build_time; m_build_time = 0;
}
if (m_requirements) {
delete m_requirements; m_requirements = 0;
}
if (m__raw_staredit_group_flags) {
delete m__raw_staredit_group_flags; m__raw_staredit_group_flags = 0;
}
if (m__io__raw_staredit_group_flags) {
for (std::vector<kaitai::kstream*>::iterator it = m__io__raw_staredit_group_flags->begin(); it != m__io__raw_staredit_group_flags->end(); ++it) {
delete *it;
}
delete m__io__raw_staredit_group_flags; m__io__raw_staredit_group_flags = 0;
}
if (m_staredit_group_flags) {
for (std::vector<staredit_group_flags_type_t*>::iterator it = m_staredit_group_flags->begin(); it != m_staredit_group_flags->end(); ++it) {
delete *it;
}
delete m_staredit_group_flags; m_staredit_group_flags = 0;
}
if (m_supply_provided) {
delete m_supply_provided; m_supply_provided = 0;
}
if (m_supply_required) {
delete m_supply_required; m_supply_required = 0;
}
if (m_space_required) {
delete m_space_required; m_space_required = 0;
}
if (m_space_provided) {
delete m_space_provided; m_space_provided = 0;
}
if (m_build_score) {
delete m_build_score; m_build_score = 0;
}
if (m_destroy_score) {
delete m_destroy_score; m_destroy_score = 0;
}
if (m_unit_map_string) {
delete m_unit_map_string; m_unit_map_string = 0;
}
if (!n_broodwar_flag) {
if (m_broodwar_flag) {
delete m_broodwar_flag; m_broodwar_flag = 0;
}
}
if (m__raw_staredit_availability_flags) {
delete m__raw_staredit_availability_flags; m__raw_staredit_availability_flags = 0;
}
if (m__io__raw_staredit_availability_flags) {
for (std::vector<kaitai::kstream*>::iterator it = m__io__raw_staredit_availability_flags->begin(); it != m__io__raw_staredit_availability_flags->end(); ++it) {
delete *it;
}
delete m__io__raw_staredit_availability_flags; m__io__raw_staredit_availability_flags = 0;
}
if (m_staredit_availability_flags) {
for (std::vector<staredit_availability_flags_type_t*>::iterator it = m_staredit_availability_flags->begin(); it != m_staredit_availability_flags->end(); ++it) {
delete *it;
}
delete m_staredit_availability_flags; m_staredit_availability_flags = 0;
}
}
units_dat_t::staredit_group_flags_type_t::staredit_group_flags_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::staredit_group_flags_type_t::_read() {
m_zerg = m__io->read_bits_int_le(1);
m_terran = m__io->read_bits_int_le(1);
m_protoss = m__io->read_bits_int_le(1);
m_men = m__io->read_bits_int_le(1);
m_building = m__io->read_bits_int_le(1);
m_factory = m__io->read_bits_int_le(1);
m_independent = m__io->read_bits_int_le(1);
m_neutral = m__io->read_bits_int_le(1);
}
units_dat_t::staredit_group_flags_type_t::~staredit_group_flags_type_t() {
_clean_up();
}
void units_dat_t::staredit_group_flags_type_t::_clean_up() {
}
units_dat_t::hit_points_type_t::hit_points_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
f_hitpoints = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::hit_points_type_t::_read() {
m_hitpoints0 = m__io->read_u2be();
m_hitpoints1 = m__io->read_u2be();
}
units_dat_t::hit_points_type_t::~hit_points_type_t() {
_clean_up();
}
void units_dat_t::hit_points_type_t::_clean_up() {
}
int32_t units_dat_t::hit_points_type_t::hitpoints() {
if (f_hitpoints)
return m_hitpoints;
m_hitpoints = (hitpoints0() + hitpoints1());
f_hitpoints = true;
return m_hitpoints;
}
units_dat_t::addon_position_type_t::addon_position_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::addon_position_type_t::_read() {
m_horizontal = m__io->read_u2le();
m_vertical = m__io->read_u2le();
}
units_dat_t::addon_position_type_t::~addon_position_type_t() {
_clean_up();
}
void units_dat_t::addon_position_type_t::_clean_up() {
}
units_dat_t::special_ability_flags_type_t::special_ability_flags_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::special_ability_flags_type_t::_read() {
m_building = m__io->read_bits_int_le(1);
m_addon = m__io->read_bits_int_le(1);
m_flyer = m__io->read_bits_int_le(1);
m_resourceminer = m__io->read_bits_int_le(1);
m_subunit = m__io->read_bits_int_le(1);
m_flyingbuilding = m__io->read_bits_int_le(1);
m_hero = m__io->read_bits_int_le(1);
m_regenerate = m__io->read_bits_int_le(1);
m_animatedidle = m__io->read_bits_int_le(1);
m_cloakable = m__io->read_bits_int_le(1);
m_twounitsinoneegg = m__io->read_bits_int_le(1);
m_singleentity = m__io->read_bits_int_le(1);
m_resourcedepot = m__io->read_bits_int_le(1);
m_resourcecontainter = m__io->read_bits_int_le(1);
m_robotic = m__io->read_bits_int_le(1);
m_detector = m__io->read_bits_int_le(1);
m_organic = m__io->read_bits_int_le(1);
m_requirescreep = m__io->read_bits_int_le(1);
m_unused = m__io->read_bits_int_le(1);
m_requirespsi = m__io->read_bits_int_le(1);
m_burrowable = m__io->read_bits_int_le(1);
m_spellcaster = m__io->read_bits_int_le(1);
m_permanentcloak = m__io->read_bits_int_le(1);
m_pickupitem = m__io->read_bits_int_le(1);
m_ignoresupplycheck = m__io->read_bits_int_le(1);
m_usemediumoverlays = m__io->read_bits_int_le(1);
m_uselargeoverlays = m__io->read_bits_int_le(1);
m_battlereactions = m__io->read_bits_int_le(1);
m_fullautoattack = m__io->read_bits_int_le(1);
m_invincible = m__io->read_bits_int_le(1);
m_mechanical = m__io->read_bits_int_le(1);
m_producesunits = m__io->read_bits_int_le(1);
}
units_dat_t::special_ability_flags_type_t::~special_ability_flags_type_t() {
_clean_up();
}
void units_dat_t::special_ability_flags_type_t::_clean_up() {
}
units_dat_t::staredit_placement_box_type_t::staredit_placement_box_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::staredit_placement_box_type_t::_read() {
m_width = m__io->read_u2le();
m_height = m__io->read_u2le();
}
units_dat_t::staredit_placement_box_type_t::~staredit_placement_box_type_t() {
_clean_up();
}
void units_dat_t::staredit_placement_box_type_t::_clean_up() {
}
units_dat_t::unit_dimension_type_t::unit_dimension_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::unit_dimension_type_t::_read() {
m_left = m__io->read_u2le();
m_up = m__io->read_u2le();
m_right = m__io->read_u2le();
m_down = m__io->read_u2le();
}
units_dat_t::unit_dimension_type_t::~unit_dimension_type_t() {
_clean_up();
}
void units_dat_t::unit_dimension_type_t::_clean_up() {
}
units_dat_t::staredit_availability_flags_type_t::staredit_availability_flags_type_t(kaitai::kstream* p__io, units_dat_t* p__parent, units_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void units_dat_t::staredit_availability_flags_type_t::_read() {
m_non_neutral = m__io->read_bits_int_le(1);
m_unit_listing = m__io->read_bits_int_le(1);
m_mission_briefing = m__io->read_bits_int_le(1);
m_player_settings = m__io->read_bits_int_le(1);
m_all_races = m__io->read_bits_int_le(1);
m_set_doodad_state = m__io->read_bits_int_le(1);
m_non_location_triggers = m__io->read_bits_int_le(1);
m_unit_hero_settings = m__io->read_bits_int_le(1);
m_location_triggers = m__io->read_bits_int_le(1);
m_brood_war_only = m__io->read_bits_int_le(1);
m__unnamed10 = m__io->read_bits_int_le(6);
}
units_dat_t::staredit_availability_flags_type_t::~staredit_availability_flags_type_t() {
_clean_up();
}
void units_dat_t::staredit_availability_flags_type_t::_clean_up() {
}
int32_t units_dat_t::sc_file_size() {
if (f_sc_file_size)
return m_sc_file_size;
m_sc_file_size = 19192;
f_sc_file_size = true;
return m_sc_file_size;
}
int32_t units_dat_t::bw_file_size() {
if (f_bw_file_size)
return m_bw_file_size;
m_bw_file_size = 19876;
f_bw_file_size = true;
return m_bw_file_size;
}
int32_t units_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
bool units_dat_t::is_format_sc() {
if (f_is_format_sc)
return m_is_format_sc;
m_is_format_sc = ((file_size() == sc_file_size()) ? (true) : (false));
f_is_format_sc = true;
return m_is_format_sc;
}
bool units_dat_t::is_format_bw() {
if (f_is_format_bw)
return m_is_format_bw;
m_is_format_bw = ((file_size() == bw_file_size()) ? (true) : (false));
f_is_format_bw = true;
return m_is_format_bw;
}
| 30,419
|
C++
|
.cpp
| 820
| 31.346341
| 180
| 0.590857
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,144
|
tileset_dddata_bin.cpp
|
Wargus_stargus/src/kaitai/tileset_dddata_bin.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "tileset_dddata_bin.h"
tileset_dddata_bin_t::tileset_dddata_bin_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, tileset_dddata_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_doodad = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_dddata_bin_t::_read() {
m_doodad = new std::vector<doodad_type_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_doodad->push_back(new doodad_type_t(m__io, this, m__root));
i++;
}
}
}
tileset_dddata_bin_t::~tileset_dddata_bin_t() {
_clean_up();
}
void tileset_dddata_bin_t::_clean_up() {
if (m_doodad) {
for (std::vector<doodad_type_t*>::iterator it = m_doodad->begin(); it != m_doodad->end(); ++it) {
delete *it;
}
delete m_doodad; m_doodad = 0;
}
}
tileset_dddata_bin_t::doodad_type_t::doodad_type_t(kaitai::kstream* p__io, tileset_dddata_bin_t* p__parent, tileset_dddata_bin_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_placing = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_dddata_bin_t::doodad_type_t::_read() {
m_placing = new std::vector<uint16_t>();
const int l_placing = 512;
for (int i = 0; i < l_placing; i++) {
m_placing->push_back(m__io->read_u2le());
}
}
tileset_dddata_bin_t::doodad_type_t::~doodad_type_t() {
_clean_up();
}
void tileset_dddata_bin_t::doodad_type_t::_clean_up() {
if (m_placing) {
delete m_placing; m_placing = 0;
}
}
| 1,776
|
C++
|
.cpp
| 60
| 24.283333
| 165
| 0.565982
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,145
|
tileset_vx4.cpp
|
Wargus_stargus/src/kaitai/tileset_vx4.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "tileset_vx4.h"
tileset_vx4_t::tileset_vx4_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, tileset_vx4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_elements = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vx4_t::_read() {
m_elements = new std::vector<megatile_type_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_elements->push_back(new megatile_type_t(m__io, this, m__root));
i++;
}
}
}
tileset_vx4_t::~tileset_vx4_t() {
_clean_up();
}
void tileset_vx4_t::_clean_up() {
if (m_elements) {
for (std::vector<megatile_type_t*>::iterator it = m_elements->begin(); it != m_elements->end(); ++it) {
delete *it;
}
delete m_elements; m_elements = 0;
}
}
tileset_vx4_t::megatile_type_t::megatile_type_t(kaitai::kstream* p__io, tileset_vx4_t* p__parent, tileset_vx4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_graphic_ref = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vx4_t::megatile_type_t::_read() {
m_graphic_ref = new std::vector<graphic_ref_type_t*>();
const int l_graphic_ref = 16;
for (int i = 0; i < l_graphic_ref; i++) {
m_graphic_ref->push_back(new graphic_ref_type_t(m__io, this, m__root));
}
}
tileset_vx4_t::megatile_type_t::~megatile_type_t() {
_clean_up();
}
void tileset_vx4_t::megatile_type_t::_clean_up() {
if (m_graphic_ref) {
for (std::vector<graphic_ref_type_t*>::iterator it = m_graphic_ref->begin(); it != m_graphic_ref->end(); ++it) {
delete *it;
}
delete m_graphic_ref; m_graphic_ref = 0;
}
}
tileset_vx4_t::graphic_ref_type_t::graphic_ref_type_t(kaitai::kstream* p__io, tileset_vx4_t::megatile_type_t* p__parent, tileset_vx4_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
f_vr4_ref = false;
f_horizontal_flip = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_vx4_t::graphic_ref_type_t::_read() {
m_vr4_ref_flip_raw = m__io->read_u2le();
}
tileset_vx4_t::graphic_ref_type_t::~graphic_ref_type_t() {
_clean_up();
}
void tileset_vx4_t::graphic_ref_type_t::_clean_up() {
}
int32_t tileset_vx4_t::graphic_ref_type_t::vr4_ref() {
if (f_vr4_ref)
return m_vr4_ref;
m_vr4_ref = (vr4_ref_flip_raw() >> 1);
f_vr4_ref = true;
return m_vr4_ref;
}
int32_t tileset_vx4_t::graphic_ref_type_t::horizontal_flip() {
if (f_horizontal_flip)
return m_horizontal_flip;
m_horizontal_flip = (vr4_ref_flip_raw() & 1);
f_horizontal_flip = true;
return m_horizontal_flip;
}
| 2,964
|
C++
|
.cpp
| 97
| 25.412371
| 171
| 0.577747
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,146
|
mapdata_dat.cpp
|
Wargus_stargus/src/kaitai/mapdata_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "mapdata_dat.h"
mapdata_dat_t::mapdata_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, mapdata_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_mission_dir = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void mapdata_dat_t::_read() {
m_mission_dir = new std::vector<uint32_t>();
{
int i = 0;
while (!m__io->is_eof()) {
m_mission_dir->push_back(m__io->read_u4le());
i++;
}
}
}
mapdata_dat_t::~mapdata_dat_t() {
_clean_up();
}
void mapdata_dat_t::_clean_up() {
if (m_mission_dir) {
delete m_mission_dir; m_mission_dir = 0;
}
}
| 824
|
C++
|
.cpp
| 31
| 21.258065
| 131
| 0.554003
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,147
|
sprites_dat.cpp
|
Wargus_stargus/src/kaitai/sprites_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "sprites_dat.h"
sprites_dat_t::sprites_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, sprites_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_image = 0;
m_health_bar = 0;
m_unknown2 = 0;
m_is_visible = 0;
m_select_circle_image_size = 0;
m_select_circle_vertical_pos = 0;
f_file_size_rest = false;
f_file_size_first_130 = false;
f_num_lines = false;
f_file_size = false;
f_record_size = false;
f_record_size_first_130 = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void sprites_dat_t::_read() {
m_image = new std::vector<uint16_t>();
const int l_image = num_lines();
for (int i = 0; i < l_image; i++) {
m_image->push_back(m__io->read_u2le());
}
m_health_bar = new std::vector<uint8_t>();
const int l_health_bar = (num_lines() - 130);
for (int i = 0; i < l_health_bar; i++) {
m_health_bar->push_back(m__io->read_u1());
}
m_unknown2 = new std::vector<uint8_t>();
const int l_unknown2 = num_lines();
for (int i = 0; i < l_unknown2; i++) {
m_unknown2->push_back(m__io->read_u1());
}
m_is_visible = new std::vector<uint8_t>();
const int l_is_visible = num_lines();
for (int i = 0; i < l_is_visible; i++) {
m_is_visible->push_back(m__io->read_u1());
}
m_select_circle_image_size = new std::vector<uint8_t>();
const int l_select_circle_image_size = (num_lines() - 130);
for (int i = 0; i < l_select_circle_image_size; i++) {
m_select_circle_image_size->push_back(m__io->read_u1());
}
m_select_circle_vertical_pos = new std::vector<uint8_t>();
const int l_select_circle_vertical_pos = (num_lines() - 130);
for (int i = 0; i < l_select_circle_vertical_pos; i++) {
m_select_circle_vertical_pos->push_back(m__io->read_u1());
}
}
sprites_dat_t::~sprites_dat_t() {
_clean_up();
}
void sprites_dat_t::_clean_up() {
if (m_image) {
delete m_image; m_image = 0;
}
if (m_health_bar) {
delete m_health_bar; m_health_bar = 0;
}
if (m_unknown2) {
delete m_unknown2; m_unknown2 = 0;
}
if (m_is_visible) {
delete m_is_visible; m_is_visible = 0;
}
if (m_select_circle_image_size) {
delete m_select_circle_image_size; m_select_circle_image_size = 0;
}
if (m_select_circle_vertical_pos) {
delete m_select_circle_vertical_pos; m_select_circle_vertical_pos = 0;
}
}
int32_t sprites_dat_t::file_size_rest() {
if (f_file_size_rest)
return m_file_size_rest;
m_file_size_rest = (file_size() - file_size_first_130());
f_file_size_rest = true;
return m_file_size_rest;
}
int32_t sprites_dat_t::file_size_first_130() {
if (f_file_size_first_130)
return m_file_size_first_130;
m_file_size_first_130 = (record_size_first_130() * 130);
f_file_size_first_130 = true;
return m_file_size_first_130;
}
int32_t sprites_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = ((file_size_rest() / record_size()) + 130);
f_num_lines = true;
return m_num_lines;
}
int32_t sprites_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
int8_t sprites_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 7;
f_record_size = true;
return m_record_size;
}
int8_t sprites_dat_t::record_size_first_130() {
if (f_record_size_first_130)
return m_record_size_first_130;
m_record_size_first_130 = 4;
f_record_size_first_130 = true;
return m_record_size_first_130;
}
| 3,890
|
C++
|
.cpp
| 121
| 27.082645
| 131
| 0.597551
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,148
|
images_dat.cpp
|
Wargus_stargus/src/kaitai/images_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "images_dat.h"
images_dat_t::images_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, images_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_grp = 0;
m_gfx_turns = 0;
m_clickable = 0;
m_use_full_iscript = 0;
m_draw_if_cloaked = 0;
m_draw_function = 0;
m_remapping = 0;
m_iscript = 0;
m_shield_overlay = 0;
m_attack_overlay = 0;
m_damage_overlay = 0;
m_special_overlay = 0;
m_landing_dust_overlay = 0;
m_lift_off_dust_overlay = 0;
f_num_lines = false;
f_record_size = false;
f_file_size = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void images_dat_t::_read() {
m_grp = new std::vector<uint32_t>();
const int l_grp = num_lines();
for (int i = 0; i < l_grp; i++) {
m_grp->push_back(m__io->read_u4le());
}
m_gfx_turns = new std::vector<uint8_t>();
const int l_gfx_turns = num_lines();
for (int i = 0; i < l_gfx_turns; i++) {
m_gfx_turns->push_back(m__io->read_u1());
}
m_clickable = new std::vector<uint8_t>();
const int l_clickable = num_lines();
for (int i = 0; i < l_clickable; i++) {
m_clickable->push_back(m__io->read_u1());
}
m_use_full_iscript = new std::vector<uint8_t>();
const int l_use_full_iscript = num_lines();
for (int i = 0; i < l_use_full_iscript; i++) {
m_use_full_iscript->push_back(m__io->read_u1());
}
m_draw_if_cloaked = new std::vector<uint8_t>();
const int l_draw_if_cloaked = num_lines();
for (int i = 0; i < l_draw_if_cloaked; i++) {
m_draw_if_cloaked->push_back(m__io->read_u1());
}
m_draw_function = new std::vector<draw_function_enum_t>();
const int l_draw_function = num_lines();
for (int i = 0; i < l_draw_function; i++) {
m_draw_function->push_back(static_cast<images_dat_t::draw_function_enum_t>(m__io->read_u1()));
}
m_remapping = new std::vector<remapping_enum_t>();
const int l_remapping = num_lines();
for (int i = 0; i < l_remapping; i++) {
m_remapping->push_back(static_cast<images_dat_t::remapping_enum_t>(m__io->read_u1()));
}
m_iscript = new std::vector<uint32_t>();
const int l_iscript = num_lines();
for (int i = 0; i < l_iscript; i++) {
m_iscript->push_back(m__io->read_u4le());
}
m_shield_overlay = new std::vector<uint32_t>();
const int l_shield_overlay = num_lines();
for (int i = 0; i < l_shield_overlay; i++) {
m_shield_overlay->push_back(m__io->read_u4le());
}
m_attack_overlay = new std::vector<uint32_t>();
const int l_attack_overlay = num_lines();
for (int i = 0; i < l_attack_overlay; i++) {
m_attack_overlay->push_back(m__io->read_u4le());
}
m_damage_overlay = new std::vector<uint32_t>();
const int l_damage_overlay = num_lines();
for (int i = 0; i < l_damage_overlay; i++) {
m_damage_overlay->push_back(m__io->read_u4le());
}
m_special_overlay = new std::vector<uint32_t>();
const int l_special_overlay = num_lines();
for (int i = 0; i < l_special_overlay; i++) {
m_special_overlay->push_back(m__io->read_u4le());
}
m_landing_dust_overlay = new std::vector<uint32_t>();
const int l_landing_dust_overlay = num_lines();
for (int i = 0; i < l_landing_dust_overlay; i++) {
m_landing_dust_overlay->push_back(m__io->read_u4le());
}
m_lift_off_dust_overlay = new std::vector<uint32_t>();
const int l_lift_off_dust_overlay = num_lines();
for (int i = 0; i < l_lift_off_dust_overlay; i++) {
m_lift_off_dust_overlay->push_back(m__io->read_u4le());
}
}
images_dat_t::~images_dat_t() {
_clean_up();
}
void images_dat_t::_clean_up() {
if (m_grp) {
delete m_grp; m_grp = 0;
}
if (m_gfx_turns) {
delete m_gfx_turns; m_gfx_turns = 0;
}
if (m_clickable) {
delete m_clickable; m_clickable = 0;
}
if (m_use_full_iscript) {
delete m_use_full_iscript; m_use_full_iscript = 0;
}
if (m_draw_if_cloaked) {
delete m_draw_if_cloaked; m_draw_if_cloaked = 0;
}
if (m_draw_function) {
delete m_draw_function; m_draw_function = 0;
}
if (m_remapping) {
delete m_remapping; m_remapping = 0;
}
if (m_iscript) {
delete m_iscript; m_iscript = 0;
}
if (m_shield_overlay) {
delete m_shield_overlay; m_shield_overlay = 0;
}
if (m_attack_overlay) {
delete m_attack_overlay; m_attack_overlay = 0;
}
if (m_damage_overlay) {
delete m_damage_overlay; m_damage_overlay = 0;
}
if (m_special_overlay) {
delete m_special_overlay; m_special_overlay = 0;
}
if (m_landing_dust_overlay) {
delete m_landing_dust_overlay; m_landing_dust_overlay = 0;
}
if (m_lift_off_dust_overlay) {
delete m_lift_off_dust_overlay; m_lift_off_dust_overlay = 0;
}
}
int32_t images_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = (file_size() / record_size());
f_num_lines = true;
return m_num_lines;
}
int8_t images_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 38;
f_record_size = true;
return m_record_size;
}
int32_t images_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
| 5,625
|
C++
|
.cpp
| 169
| 27.804734
| 128
| 0.581788
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,149
|
techdata_dat.cpp
|
Wargus_stargus/src/kaitai/techdata_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "techdata_dat.h"
techdata_dat_t::techdata_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, techdata_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_mineral_cost = 0;
m_vespene_cost = 0;
m_research_time = 0;
m_energy_required = 0;
m_unknown4 = 0;
m_icon = 0;
m_label = 0;
m_race = 0;
m_unused = 0;
m_broodwar_flag = 0;
f_record_count_broodwar = false;
f_record_count = false;
f_num_lines = false;
f_has_broodwar_flag = false;
f_file_size = false;
f_record_size = false;
f_record_size_broodwar = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void techdata_dat_t::_read() {
m_mineral_cost = new std::vector<uint16_t>();
const int l_mineral_cost = num_lines();
for (int i = 0; i < l_mineral_cost; i++) {
m_mineral_cost->push_back(m__io->read_u2le());
}
m_vespene_cost = new std::vector<uint16_t>();
const int l_vespene_cost = num_lines();
for (int i = 0; i < l_vespene_cost; i++) {
m_vespene_cost->push_back(m__io->read_u2le());
}
m_research_time = new std::vector<uint16_t>();
const int l_research_time = num_lines();
for (int i = 0; i < l_research_time; i++) {
m_research_time->push_back(m__io->read_u2le());
}
m_energy_required = new std::vector<uint16_t>();
const int l_energy_required = num_lines();
for (int i = 0; i < l_energy_required; i++) {
m_energy_required->push_back(m__io->read_u2le());
}
m_unknown4 = new std::vector<uint32_t>();
const int l_unknown4 = num_lines();
for (int i = 0; i < l_unknown4; i++) {
m_unknown4->push_back(m__io->read_u4le());
}
m_icon = new std::vector<uint16_t>();
const int l_icon = num_lines();
for (int i = 0; i < l_icon; i++) {
m_icon->push_back(m__io->read_u2le());
}
m_label = new std::vector<uint16_t>();
const int l_label = num_lines();
for (int i = 0; i < l_label; i++) {
m_label->push_back(m__io->read_u2le());
}
m_race = new std::vector<uint8_t>();
const int l_race = num_lines();
for (int i = 0; i < l_race; i++) {
m_race->push_back(m__io->read_u1());
}
m_unused = new std::vector<uint8_t>();
const int l_unused = num_lines();
for (int i = 0; i < l_unused; i++) {
m_unused->push_back(m__io->read_u1());
}
n_broodwar_flag = true;
if (has_broodwar_flag() == true) {
n_broodwar_flag = false;
m_broodwar_flag = new std::vector<uint8_t>();
const int l_broodwar_flag = num_lines();
for (int i = 0; i < l_broodwar_flag; i++) {
m_broodwar_flag->push_back(m__io->read_u1());
}
}
}
techdata_dat_t::~techdata_dat_t() {
_clean_up();
}
void techdata_dat_t::_clean_up() {
if (m_mineral_cost) {
delete m_mineral_cost; m_mineral_cost = 0;
}
if (m_vespene_cost) {
delete m_vespene_cost; m_vespene_cost = 0;
}
if (m_research_time) {
delete m_research_time; m_research_time = 0;
}
if (m_energy_required) {
delete m_energy_required; m_energy_required = 0;
}
if (m_unknown4) {
delete m_unknown4; m_unknown4 = 0;
}
if (m_icon) {
delete m_icon; m_icon = 0;
}
if (m_label) {
delete m_label; m_label = 0;
}
if (m_race) {
delete m_race; m_race = 0;
}
if (m_unused) {
delete m_unused; m_unused = 0;
}
if (!n_broodwar_flag) {
if (m_broodwar_flag) {
delete m_broodwar_flag; m_broodwar_flag = 0;
}
}
}
int32_t techdata_dat_t::record_count_broodwar() {
if (f_record_count_broodwar)
return m_record_count_broodwar;
m_record_count_broodwar = (file_size() / record_size_broodwar());
f_record_count_broodwar = true;
return m_record_count_broodwar;
}
int32_t techdata_dat_t::record_count() {
if (f_record_count)
return m_record_count;
m_record_count = (file_size() / record_size());
f_record_count = true;
return m_record_count;
}
int32_t techdata_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = ((kaitai::kstream::mod(file_size(), record_size()) == 0) ? (record_count()) : (record_count_broodwar()));
f_num_lines = true;
return m_num_lines;
}
bool techdata_dat_t::has_broodwar_flag() {
if (f_has_broodwar_flag)
return m_has_broodwar_flag;
m_has_broodwar_flag = ((kaitai::kstream::mod(file_size(), record_size()) == 0) ? (false) : (true));
f_has_broodwar_flag = true;
return m_has_broodwar_flag;
}
int32_t techdata_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
int8_t techdata_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 18;
f_record_size = true;
return m_record_size;
}
int8_t techdata_dat_t::record_size_broodwar() {
if (f_record_size_broodwar)
return m_record_size_broodwar;
m_record_size_broodwar = 19;
f_record_size_broodwar = true;
return m_record_size_broodwar;
}
| 5,350
|
C++
|
.cpp
| 171
| 25.859649
| 134
| 0.58072
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,150
|
orders_dat.cpp
|
Wargus_stargus/src/kaitai/orders_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "orders_dat.h"
orders_dat_t::orders_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, orders_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_label = 0;
m_use_weapon_targeting = 0;
m_unknown2 = 0;
m_unknown3 = 0;
m_unknown4 = 0;
m_unknown5 = 0;
m_interruptible = 0;
m_unknown7 = 0;
m_queueable = 0;
m_unknown9 = 0;
m_unknown10 = 0;
m_unknown11 = 0;
m_unknown12 = 0;
m_targeting = 0;
m_energy = 0;
m_animation = 0;
m_highlight = 0;
m_unknown17 = 0;
m_obscured_order = 0;
f_num_lines = false;
f_record_size = false;
f_file_size = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void orders_dat_t::_read() {
m_label = new std::vector<uint16_t>();
const int l_label = num_lines();
for (int i = 0; i < l_label; i++) {
m_label->push_back(m__io->read_u2le());
}
m_use_weapon_targeting = new std::vector<uint8_t>();
const int l_use_weapon_targeting = num_lines();
for (int i = 0; i < l_use_weapon_targeting; i++) {
m_use_weapon_targeting->push_back(m__io->read_u1());
}
m_unknown2 = new std::vector<uint8_t>();
const int l_unknown2 = num_lines();
for (int i = 0; i < l_unknown2; i++) {
m_unknown2->push_back(m__io->read_u1());
}
m_unknown3 = new std::vector<uint8_t>();
const int l_unknown3 = num_lines();
for (int i = 0; i < l_unknown3; i++) {
m_unknown3->push_back(m__io->read_u1());
}
m_unknown4 = new std::vector<uint8_t>();
const int l_unknown4 = num_lines();
for (int i = 0; i < l_unknown4; i++) {
m_unknown4->push_back(m__io->read_u1());
}
m_unknown5 = new std::vector<uint8_t>();
const int l_unknown5 = num_lines();
for (int i = 0; i < l_unknown5; i++) {
m_unknown5->push_back(m__io->read_u1());
}
m_interruptible = new std::vector<uint8_t>();
const int l_interruptible = num_lines();
for (int i = 0; i < l_interruptible; i++) {
m_interruptible->push_back(m__io->read_u1());
}
m_unknown7 = new std::vector<uint8_t>();
const int l_unknown7 = num_lines();
for (int i = 0; i < l_unknown7; i++) {
m_unknown7->push_back(m__io->read_u1());
}
m_queueable = new std::vector<uint8_t>();
const int l_queueable = num_lines();
for (int i = 0; i < l_queueable; i++) {
m_queueable->push_back(m__io->read_u1());
}
m_unknown9 = new std::vector<uint8_t>();
const int l_unknown9 = num_lines();
for (int i = 0; i < l_unknown9; i++) {
m_unknown9->push_back(m__io->read_u1());
}
m_unknown10 = new std::vector<uint8_t>();
const int l_unknown10 = num_lines();
for (int i = 0; i < l_unknown10; i++) {
m_unknown10->push_back(m__io->read_u1());
}
m_unknown11 = new std::vector<uint8_t>();
const int l_unknown11 = num_lines();
for (int i = 0; i < l_unknown11; i++) {
m_unknown11->push_back(m__io->read_u1());
}
m_unknown12 = new std::vector<uint8_t>();
const int l_unknown12 = num_lines();
for (int i = 0; i < l_unknown12; i++) {
m_unknown12->push_back(m__io->read_u1());
}
m_targeting = new std::vector<uint8_t>();
const int l_targeting = num_lines();
for (int i = 0; i < l_targeting; i++) {
m_targeting->push_back(m__io->read_u1());
}
m_energy = new std::vector<uint8_t>();
const int l_energy = num_lines();
for (int i = 0; i < l_energy; i++) {
m_energy->push_back(m__io->read_u1());
}
m_animation = new std::vector<uint8_t>();
const int l_animation = num_lines();
for (int i = 0; i < l_animation; i++) {
m_animation->push_back(m__io->read_u1());
}
m_highlight = new std::vector<uint16_t>();
const int l_highlight = num_lines();
for (int i = 0; i < l_highlight; i++) {
m_highlight->push_back(m__io->read_u2le());
}
m_unknown17 = new std::vector<uint16_t>();
const int l_unknown17 = num_lines();
for (int i = 0; i < l_unknown17; i++) {
m_unknown17->push_back(m__io->read_u2le());
}
m_obscured_order = new std::vector<uint8_t>();
const int l_obscured_order = num_lines();
for (int i = 0; i < l_obscured_order; i++) {
m_obscured_order->push_back(m__io->read_u1());
}
}
orders_dat_t::~orders_dat_t() {
_clean_up();
}
void orders_dat_t::_clean_up() {
if (m_label) {
delete m_label; m_label = 0;
}
if (m_use_weapon_targeting) {
delete m_use_weapon_targeting; m_use_weapon_targeting = 0;
}
if (m_unknown2) {
delete m_unknown2; m_unknown2 = 0;
}
if (m_unknown3) {
delete m_unknown3; m_unknown3 = 0;
}
if (m_unknown4) {
delete m_unknown4; m_unknown4 = 0;
}
if (m_unknown5) {
delete m_unknown5; m_unknown5 = 0;
}
if (m_interruptible) {
delete m_interruptible; m_interruptible = 0;
}
if (m_unknown7) {
delete m_unknown7; m_unknown7 = 0;
}
if (m_queueable) {
delete m_queueable; m_queueable = 0;
}
if (m_unknown9) {
delete m_unknown9; m_unknown9 = 0;
}
if (m_unknown10) {
delete m_unknown10; m_unknown10 = 0;
}
if (m_unknown11) {
delete m_unknown11; m_unknown11 = 0;
}
if (m_unknown12) {
delete m_unknown12; m_unknown12 = 0;
}
if (m_targeting) {
delete m_targeting; m_targeting = 0;
}
if (m_energy) {
delete m_energy; m_energy = 0;
}
if (m_animation) {
delete m_animation; m_animation = 0;
}
if (m_highlight) {
delete m_highlight; m_highlight = 0;
}
if (m_unknown17) {
delete m_unknown17; m_unknown17 = 0;
}
if (m_obscured_order) {
delete m_obscured_order; m_obscured_order = 0;
}
}
int32_t orders_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = (file_size() / record_size());
f_num_lines = true;
return m_num_lines;
}
int8_t orders_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 22;
f_record_size = true;
return m_record_size;
}
int32_t orders_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
| 6,536
|
C++
|
.cpp
| 214
| 24.976636
| 128
| 0.561856
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,151
|
sfxdata_dat.cpp
|
Wargus_stargus/src/kaitai/sfxdata_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "sfxdata_dat.h"
sfxdata_dat_t::sfxdata_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, sfxdata_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_sound_file = 0;
m_unknown1 = 0;
m_unknown2 = 0;
m_unknown3 = 0;
m_unknown4 = 0;
f_num_lines = false;
f_record_size = false;
f_file_size = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void sfxdata_dat_t::_read() {
m_sound_file = new std::vector<uint32_t>();
const int l_sound_file = num_lines();
for (int i = 0; i < l_sound_file; i++) {
m_sound_file->push_back(m__io->read_u4le());
}
m_unknown1 = new std::vector<uint8_t>();
const int l_unknown1 = num_lines();
for (int i = 0; i < l_unknown1; i++) {
m_unknown1->push_back(m__io->read_u1());
}
m_unknown2 = new std::vector<uint8_t>();
const int l_unknown2 = num_lines();
for (int i = 0; i < l_unknown2; i++) {
m_unknown2->push_back(m__io->read_u1());
}
m_unknown3 = new std::vector<uint16_t>();
const int l_unknown3 = num_lines();
for (int i = 0; i < l_unknown3; i++) {
m_unknown3->push_back(m__io->read_u2le());
}
m_unknown4 = new std::vector<uint8_t>();
const int l_unknown4 = num_lines();
for (int i = 0; i < l_unknown4; i++) {
m_unknown4->push_back(m__io->read_u1());
}
}
sfxdata_dat_t::~sfxdata_dat_t() {
_clean_up();
}
void sfxdata_dat_t::_clean_up() {
if (m_sound_file) {
delete m_sound_file; m_sound_file = 0;
}
if (m_unknown1) {
delete m_unknown1; m_unknown1 = 0;
}
if (m_unknown2) {
delete m_unknown2; m_unknown2 = 0;
}
if (m_unknown3) {
delete m_unknown3; m_unknown3 = 0;
}
if (m_unknown4) {
delete m_unknown4; m_unknown4 = 0;
}
}
int32_t sfxdata_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = (file_size() / record_size());
f_num_lines = true;
return m_num_lines;
}
int8_t sfxdata_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 9;
f_record_size = true;
return m_record_size;
}
int32_t sfxdata_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
| 2,515
|
C++
|
.cpp
| 88
| 23.477273
| 131
| 0.569065
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,152
|
upgrades_dat.cpp
|
Wargus_stargus/src/kaitai/upgrades_dat.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "upgrades_dat.h"
upgrades_dat_t::upgrades_dat_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, upgrades_dat_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_mineral_cost_base = 0;
m_mineral_cost_factor = 0;
m_vespene_cost_base = 0;
m_vespene_cost_factor = 0;
m_research_time_base = 0;
m_research_time_factor = 0;
m_unknown6 = 0;
m_icon = 0;
m_label = 0;
m_race = 0;
m_max_repeats = 0;
m_broodwar_flags = 0;
f_record_count_broodwar = false;
f_record_count = false;
f_num_lines = false;
f_has_broodwar_flag = false;
f_file_size = false;
f_record_size = false;
f_record_size_broodwar = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void upgrades_dat_t::_read() {
m_mineral_cost_base = new std::vector<uint16_t>();
const int l_mineral_cost_base = num_lines();
for (int i = 0; i < l_mineral_cost_base; i++) {
m_mineral_cost_base->push_back(m__io->read_u2le());
}
m_mineral_cost_factor = new std::vector<uint16_t>();
const int l_mineral_cost_factor = num_lines();
for (int i = 0; i < l_mineral_cost_factor; i++) {
m_mineral_cost_factor->push_back(m__io->read_u2le());
}
m_vespene_cost_base = new std::vector<uint16_t>();
const int l_vespene_cost_base = num_lines();
for (int i = 0; i < l_vespene_cost_base; i++) {
m_vespene_cost_base->push_back(m__io->read_u2le());
}
m_vespene_cost_factor = new std::vector<uint16_t>();
const int l_vespene_cost_factor = num_lines();
for (int i = 0; i < l_vespene_cost_factor; i++) {
m_vespene_cost_factor->push_back(m__io->read_u2le());
}
m_research_time_base = new std::vector<uint16_t>();
const int l_research_time_base = num_lines();
for (int i = 0; i < l_research_time_base; i++) {
m_research_time_base->push_back(m__io->read_u2le());
}
m_research_time_factor = new std::vector<uint16_t>();
const int l_research_time_factor = num_lines();
for (int i = 0; i < l_research_time_factor; i++) {
m_research_time_factor->push_back(m__io->read_u2le());
}
m_unknown6 = new std::vector<uint16_t>();
const int l_unknown6 = num_lines();
for (int i = 0; i < l_unknown6; i++) {
m_unknown6->push_back(m__io->read_u2le());
}
m_icon = new std::vector<uint16_t>();
const int l_icon = num_lines();
for (int i = 0; i < l_icon; i++) {
m_icon->push_back(m__io->read_u2le());
}
m_label = new std::vector<uint16_t>();
const int l_label = num_lines();
for (int i = 0; i < l_label; i++) {
m_label->push_back(m__io->read_u2le());
}
m_race = new std::vector<uint8_t>();
const int l_race = num_lines();
for (int i = 0; i < l_race; i++) {
m_race->push_back(m__io->read_u1());
}
m_max_repeats = new std::vector<uint8_t>();
const int l_max_repeats = num_lines();
for (int i = 0; i < l_max_repeats; i++) {
m_max_repeats->push_back(m__io->read_u1());
}
n_broodwar_flags = true;
if (has_broodwar_flag() == true) {
n_broodwar_flags = false;
m_broodwar_flags = new std::vector<uint8_t>();
const int l_broodwar_flags = num_lines();
for (int i = 0; i < l_broodwar_flags; i++) {
m_broodwar_flags->push_back(m__io->read_u1());
}
}
}
upgrades_dat_t::~upgrades_dat_t() {
_clean_up();
}
void upgrades_dat_t::_clean_up() {
if (m_mineral_cost_base) {
delete m_mineral_cost_base; m_mineral_cost_base = 0;
}
if (m_mineral_cost_factor) {
delete m_mineral_cost_factor; m_mineral_cost_factor = 0;
}
if (m_vespene_cost_base) {
delete m_vespene_cost_base; m_vespene_cost_base = 0;
}
if (m_vespene_cost_factor) {
delete m_vespene_cost_factor; m_vespene_cost_factor = 0;
}
if (m_research_time_base) {
delete m_research_time_base; m_research_time_base = 0;
}
if (m_research_time_factor) {
delete m_research_time_factor; m_research_time_factor = 0;
}
if (m_unknown6) {
delete m_unknown6; m_unknown6 = 0;
}
if (m_icon) {
delete m_icon; m_icon = 0;
}
if (m_label) {
delete m_label; m_label = 0;
}
if (m_race) {
delete m_race; m_race = 0;
}
if (m_max_repeats) {
delete m_max_repeats; m_max_repeats = 0;
}
if (!n_broodwar_flags) {
if (m_broodwar_flags) {
delete m_broodwar_flags; m_broodwar_flags = 0;
}
}
}
int32_t upgrades_dat_t::record_count_broodwar() {
if (f_record_count_broodwar)
return m_record_count_broodwar;
m_record_count_broodwar = (file_size() / record_size_broodwar());
f_record_count_broodwar = true;
return m_record_count_broodwar;
}
int32_t upgrades_dat_t::record_count() {
if (f_record_count)
return m_record_count;
m_record_count = (file_size() / record_size());
f_record_count = true;
return m_record_count;
}
int32_t upgrades_dat_t::num_lines() {
if (f_num_lines)
return m_num_lines;
m_num_lines = ((kaitai::kstream::mod(file_size(), record_size()) == 0) ? (record_count()) : (record_count_broodwar()));
f_num_lines = true;
return m_num_lines;
}
bool upgrades_dat_t::has_broodwar_flag() {
if (f_has_broodwar_flag)
return m_has_broodwar_flag;
m_has_broodwar_flag = ((kaitai::kstream::mod(file_size(), record_size()) == 0) ? (false) : (true));
f_has_broodwar_flag = true;
return m_has_broodwar_flag;
}
int32_t upgrades_dat_t::file_size() {
if (f_file_size)
return m_file_size;
m_file_size = _io()->size();
f_file_size = true;
return m_file_size;
}
int8_t upgrades_dat_t::record_size() {
if (f_record_size)
return m_record_size;
m_record_size = 20;
f_record_size = true;
return m_record_size;
}
int8_t upgrades_dat_t::record_size_broodwar() {
if (f_record_size_broodwar)
return m_record_size_broodwar;
m_record_size_broodwar = 21;
f_record_size_broodwar = true;
return m_record_size_broodwar;
}
| 6,291
|
C++
|
.cpp
| 189
| 27.814815
| 134
| 0.59238
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,153
|
file_tbl.cpp
|
Wargus_stargus/src/kaitai/file_tbl.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "file_tbl.h"
file_tbl_t::file_tbl_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, file_tbl_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_ofs_files = 0;
m_tbl_entries = 0;
f_tbl_entries = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void file_tbl_t::_read() {
m_num_offsets = m__io->read_u2le();
m_ofs_files = new std::vector<uint16_t>();
const int l_ofs_files = num_offsets();
for (int i = 0; i < l_ofs_files; i++) {
m_ofs_files->push_back(m__io->read_u2le());
}
}
file_tbl_t::~file_tbl_t() {
_clean_up();
}
void file_tbl_t::_clean_up() {
if (m_ofs_files) {
delete m_ofs_files; m_ofs_files = 0;
}
if (f_tbl_entries) {
if (m_tbl_entries) {
for (std::vector<tbl_entry_t*>::iterator it = m_tbl_entries->begin(); it != m_tbl_entries->end(); ++it) {
delete *it;
}
delete m_tbl_entries; m_tbl_entries = 0;
}
}
}
file_tbl_t::tbl_entry_t::tbl_entry_t(uint16_t p_i, kaitai::kstream* p__io, file_tbl_t* p__parent, file_tbl_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_i = p_i;
m_entry = 0;
f_len = false;
f_dyn_end = false;
f_entry = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void file_tbl_t::tbl_entry_t::_read() {
}
file_tbl_t::tbl_entry_t::~tbl_entry_t() {
_clean_up();
}
void file_tbl_t::tbl_entry_t::_clean_up() {
if (f_entry) {
if (m_entry) {
delete m_entry; m_entry = 0;
}
}
}
int32_t file_tbl_t::tbl_entry_t::len() {
if (f_len)
return m_len;
m_len = (_parent()->ofs_files()->at((i() + 1)) - _parent()->ofs_files()->at(i()));
f_len = true;
return m_len;
}
int32_t file_tbl_t::tbl_entry_t::dyn_end() {
if (f_dyn_end)
return m_dyn_end;
m_dyn_end = (((i() + 1) < _parent()->num_offsets()) ? (len()) : ((_io()->size() - _parent()->ofs_files()->at(i()))));
f_dyn_end = true;
return m_dyn_end;
}
std::vector<uint8_t>* file_tbl_t::tbl_entry_t::entry() {
if (f_entry)
return m_entry;
std::streampos _pos = m__io->pos();
m__io->seek(_parent()->ofs_files()->at(i()));
m_entry = new std::vector<uint8_t>();
const int l_entry = dyn_end();
for (int i = 0; i < l_entry; i++) {
m_entry->push_back(m__io->read_u1());
}
m__io->seek(_pos);
f_entry = true;
return m_entry;
}
std::vector<file_tbl_t::tbl_entry_t*>* file_tbl_t::tbl_entries() {
if (f_tbl_entries)
return m_tbl_entries;
m_tbl_entries = new std::vector<tbl_entry_t*>();
const int l_tbl_entries = num_offsets();
for (int i = 0; i < l_tbl_entries; i++) {
m_tbl_entries->push_back(new tbl_entry_t(i, m__io, this, m__root));
}
f_tbl_entries = true;
return m_tbl_entries;
}
| 3,078
|
C++
|
.cpp
| 105
| 24.057143
| 145
| 0.536173
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,154
|
tileset_cv5.cpp
|
Wargus_stargus/src/kaitai/tileset_cv5.cpp
|
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "tileset_cv5.h"
tileset_cv5_t::tileset_cv5_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, tileset_cv5_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_elements = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_cv5_t::_read() {
m_elements = new std::vector<group_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_elements->push_back(new group_t(m__io, this, m__root));
i++;
}
}
}
tileset_cv5_t::~tileset_cv5_t() {
_clean_up();
}
void tileset_cv5_t::_clean_up() {
if (m_elements) {
for (std::vector<group_t*>::iterator it = m_elements->begin(); it != m_elements->end(); ++it) {
delete *it;
}
delete m_elements; m_elements = 0;
}
}
tileset_cv5_t::group_t::group_t(kaitai::kstream* p__io, tileset_cv5_t* p__parent, tileset_cv5_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_ground = 0;
m_megatile_references = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_cv5_t::group_t::_read() {
m_doodad = m__io->read_u2le();
m_ground = new ground_nibbles_t(m__io, this, m__root);
m_unknown1 = m__io->read_u2le();
m_unknown2 = m__io->read_u2le();
m_unknown3 = m__io->read_u2le();
m_unknown4 = m__io->read_u2le();
m_unknown5 = m__io->read_u2le();
m_unknown6 = m__io->read_u2le();
m_unknown7 = m__io->read_u2le();
m_unknown8 = m__io->read_u2le();
m_megatile_references = new std::vector<uint16_t>();
const int l_megatile_references = 16;
for (int i = 0; i < l_megatile_references; i++) {
m_megatile_references->push_back(m__io->read_u2le());
}
}
tileset_cv5_t::group_t::~group_t() {
_clean_up();
}
void tileset_cv5_t::group_t::_clean_up() {
if (m_ground) {
delete m_ground; m_ground = 0;
}
if (m_megatile_references) {
delete m_megatile_references; m_megatile_references = 0;
}
}
tileset_cv5_t::ground_nibbles_t::ground_nibbles_t(kaitai::kstream* p__io, tileset_cv5_t::group_t* p__parent, tileset_cv5_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void tileset_cv5_t::ground_nibbles_t::_read() {
m_buildable = m__io->read_bits_int_le(4);
m_ground_type = m__io->read_bits_int_le(4);
m_unknown1 = m__io->read_bits_int_le(4);
m_ground_height = m__io->read_bits_int_le(4);
}
tileset_cv5_t::ground_nibbles_t::~ground_nibbles_t() {
_clean_up();
}
void tileset_cv5_t::ground_nibbles_t::_clean_up() {
}
| 2,880
|
C++
|
.cpp
| 95
| 25.231579
| 159
| 0.569159
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,156
|
opcode_list_type.cpp
|
Wargus_stargus/src/kaitai/opcode_list_type.cpp
|
/*
* opcode_list_type.cpp
*
* Author: Andreas Volz
*/
#include "opcode_list_type.h"
#include "iscript_bin.h"
#include <iostream>
using namespace std;
opcode_list_type_t::opcode_list_type_t(kaitai::kstruct* p__parent, iscript_bin_t* p__root, kaitai::kstream* p__io) :
kaitai::kstruct(p__io),
m__root(p__root),
m__parent(p__parent),
m_pos(m__io->pos()),
m_opcode_list(nullptr)
{
}
opcode_list_type_t::~opcode_list_type_t()
{
_clean_up();
}
std::vector<kaitai::kstruct*>* opcode_list_type_t::read_list(std::unordered_set<uint16_t> scpe_offset_table)
{
if (m_opcode_list)
{
return m_opcode_list;
}
else
{
m_opcode_list = new std::vector<kaitai::kstruct*>();
}
m_scpe_offset_table = scpe_offset_table;
std::streampos _pos = m__io->pos();
m__io->seek(m_pos);
try
{
_read();
}
catch(...)
{
_clean_up();
throw;
}
m__io->seek(_pos);
return m_opcode_list;
}
void opcode_list_type_t::_read()
{
int scpe_opcode_offset = 0;
bool end_criteria = false;
do
{
iscript_bin_t::opcode_type_t *opcode = new iscript_bin_t::opcode_type_t(m__io, m__parent, m__root);
//cout << "_read::code: " << hex << opcode->code() << endl;
m_opcode_list->push_back(opcode);
// set next offset position
scpe_opcode_offset = m__io->pos();
if(m_scpe_offset_table.find(scpe_opcode_offset) != m_scpe_offset_table.end())
{
end_criteria = true;
}
// for now stop when GOTO opcode is found
if(opcode->code() == iscript_bin_t::opcode_t::OPCODE_GOTO)
{
end_criteria = true;
}
}
while(!end_criteria);
}
void opcode_list_type_t::_clean_up()
{
delete m_opcode_list;
}
| 1,682
|
C++
|
.cpp
| 73
| 19.863014
| 116
| 0.631117
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,157
|
TilesetHub.cpp
|
Wargus_stargus/src/tileset/TilesetHub.cpp
|
/*
* TilesetHub.cpp
*
* Author: Andreas Volz
*/
// project
#include "TilesetHub.h"
#include "PaletteImage.h"
#include "PngExporter.h"
#include "MegaTile.h"
#include "FileUtil.h"
#include "luagen.h"
#include "Preferences.h"
#include "Hurricane.h"
// system
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
namespace tileset
{
TilesetHub::TilesetHub(std::shared_ptr<Hurricane> hurricane, const std::string &arcfile) :
KaitaiConverter(hurricane)
{
init(arcfile);
}
TilesetHub::~TilesetHub()
{
}
/*m_iscript_stream = mHurricane->extractStream(sc_iscript_bin);
m_iscript_ks = make_shared<kaitai::kstream>(&*m_iscript_stream);
iscript = make_shared<iscript_bin_t>(m_iscript_ks.get());
*/
void TilesetHub::init(const std::string &arcfile)
{
m_cv5_stream = mHurricane->extractStream(arcfile + ".cv5");
m_cv5_ks = make_shared<kaitai::kstream>(&*m_cv5_stream);
cv5 = make_shared<tileset_cv5_t>(m_cv5_ks.get());
m_vx4_stream = mHurricane->extractStream(arcfile + ".vx4");
m_vx4_ks = make_shared<kaitai::kstream>(&*m_vx4_stream);
vx4 = make_shared<tileset_vx4_t>(m_vx4_ks.get());
m_vf4_stream = mHurricane->extractStream(arcfile + ".vf4");
m_vf4_ks = make_shared<kaitai::kstream>(&*m_vf4_stream);
vf4 = make_shared<tileset_vf4_t>(m_vf4_ks.get());
m_vr4_stream = mHurricane->extractStream(arcfile + ".vr4");
m_vr4_ks = make_shared<kaitai::kstream>(&*m_vr4_stream);
vr4 = make_shared<tileset_vr4_t>(m_vr4_ks.get());
}
bool TilesetHub::convert(std::shared_ptr<AbstractPalette> palette, Storage storage)
{
if(!vx4) // if it isn't available just return false
{
return false;
}
if(!palette) // if something wrong with palette just return false
{
return false;
}
unsigned int num_tiles = vx4->elements()->size();
int tiles_width = 16;
int tiles_height = static_cast<int>(ceil(static_cast<float>(num_tiles) / static_cast<float>(tiles_width)));
TiledPaletteImage ultraTile(Size(tiles_width, tiles_height), Size(32,32));
for(unsigned int i = 0; i < num_tiles; i++)
{
MegaTile mega(*this, i);
ultraTile.copyTile(*mega.getImage(), i);
}
// FIXME: I don't like the path handling in this case. Needs to be changed!
string save_png(storage.getFullPath() + "/" + storage.getFilename() + ".png");
CheckPath(save_png);
return PngExporter::save(save_png, ultraTile, palette, 0);
}
void TilesetHub::generateLua(const std::string &name, const std::string &image, Storage luafile)
{
if(!cv5) // if it isn't available just return with no action
{
return;
}
unsigned int num_cv5 = cv5->elements()->size();
int num_doodad = 0;
int num_normal = 0;
ofstream lua_tileset_stream;
CheckPath(luafile.getFullPath());
lua_tileset_stream.open (luafile.getFullPath());
vector<string> tile_slots_vector;
for(unsigned int i = 0; i < num_cv5; i++)
{
tileset_cv5_t::group_t* group = cv5->elements()->at(i);
if(group->doodad() != 0)
{
num_doodad++;
//cout << "doodad(" << i << "): ";
}
else
{
num_normal++;
//cout << "normal(" << i << "): ";
}
std::vector<uint16_t>* vx4_vf4_ref = group->megatile_references();
vector<string> tile_solids_vector;
for(auto elem : *vx4_vf4_ref)
{
//cout << to_string(elem);
tileset_vf4_t::minitile_t* minitile = vf4->elements()->at(elem);
std::string subtilePassableFlags = "";
for(auto flags : *minitile->flags())
{
if (flags->walkable()) {
subtilePassableFlags += "p";
} else {
subtilePassableFlags += "u";
}
}
tile_solids_vector.push_back(to_string(elem));
tile_solids_vector.push_back(lg::table(lg::quote(subtilePassableFlags)));
//cout << ", ";
}
//cout << endl;
string tile_solids_str = lg::params(tile_solids_vector);
string solid_str = lg::line(lg::tilesetSlotEntry("solid", {"light-grass", "land"}, {tile_solids_str}));
tile_slots_vector.push_back(solid_str);
}
string tile_slots_str = lg::params(tile_slots_vector);
string lua_tileset_str = lg::DefineTileset(name, image, {tile_slots_str});
//cout << lua_tileset_str << endl;
lua_tileset_stream << lua_tileset_str;
lua_tileset_stream.close();
//cout << "num_doodad: " << num_doodad << endl;
//cout << "num_normal: " << num_normal << endl;
}
} /* namespace tileset */
| 4,393
|
C++
|
.cpp
| 131
| 29.839695
| 109
| 0.66335
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,158
|
TiledPaletteImage.cpp
|
Wargus_stargus/src/tileset/TiledPaletteImage.cpp
|
/*
* TiledPaletteImage.cpp
*
* Author: Andreas Volz
*/
#include "TiledPaletteImage.h"
#include "Logger.h"
namespace tileset
{
static Logger logger = Logger("startool.tileset.TiledPaletteImage");
TiledPaletteImage::TiledPaletteImage(const Size &tileSize, const Size &subtileSize) :
PaletteImage(tileSize * subtileSize),
mTileSize(tileSize),
mSubtileSize(subtileSize)
{
}
TiledPaletteImage::~TiledPaletteImage()
{
}
void TiledPaletteImage::copyTile(const PaletteImage &palette_image, size_t index, bool horizontal_flip)
{
int y = 0;
int x = 0;
// if index is out of data size that return Pos(0, 0) as fail safe
if((int)index < (getSize().getWidth() * getSize().getHeight()) /
(palette_image.getSize().getWidth() * palette_image.getSize().getHeight()))
{
y = index / (getSize().getWidth() / palette_image.getSize().getWidth());
x = index % (getSize().getWidth() / palette_image.getSize().getWidth());
}
Pos rel_pos(x,y);
copyTile(palette_image, rel_pos, horizontal_flip);
}
void TiledPaletteImage::copyTile(const PaletteImage &palette_image, const Pos &pos, bool horizontal_flip)
{
if(pos.getX() < mTileSize.getWidth() || pos.getY() < mTileSize.getWidth())
{
for(int x = 0; x < palette_image.getSize().getWidth(); x++)
{
for(int y = 0; y < palette_image.getSize().getHeight(); y++)
{
unsigned char pixel = palette_image.at(Pos(x, y));
int x_flip = x;
if(horizontal_flip)
{
x_flip = palette_image.getSize().getWidth() - 1 - x;
}
at(calcAbsolutePos(pos, Pos(x_flip, y))) = pixel;
}
}
}
else
{
LOG4CXX_WARN(logger, "copyTile() out of range!");
}
}
const Pos TiledPaletteImage::calcAbsolutePos(const Pos &tile_pos, const Pos &relative_pos)
{
return Pos(tile_pos.getX() * mSubtileSize.getWidth() + relative_pos.getX(), tile_pos.getY() * mSubtileSize.getHeight() + relative_pos.getY());
}
} /* namespace tileset */
| 1,979
|
C++
|
.cpp
| 61
| 28.688525
| 144
| 0.674027
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,159
|
MegaTile.cpp
|
Wargus_stargus/src/tileset/MegaTile.cpp
|
/*
* MegaTile.cpp
*
* Author: Andreas Volz
*/
// project
#include "MegaTile.h"
#include "kaitai/tileset_vr4.h"
#include "kaitai/tileset_vx4.h"
#include "Logger.h"
// system
#include <string>
#include <iostream>
using namespace std;
namespace tileset
{
static Logger logger = Logger("startool.tileset.MegaTile");
MegaTile::MegaTile(TilesetHub &tilesethub, size_t element) :
mTilesetHub(tilesethub),
mElement(element)
{
generateTiles();
}
MegaTile::~MegaTile()
{
}
void MegaTile::generateTiles()
{
mPaletteImage = make_shared<TiledPaletteImage>(Size(4, 4), Size(8, 8));
tileset_vx4_t::megatile_type_t *megatile = mTilesetHub.vx4->elements()->at(mElement);
std::vector<tileset_vx4_t::graphic_ref_type_t *> *vx4_graphic_ref = megatile->graphic_ref();
unsigned int n = 0;
for (auto g : *vx4_graphic_ref)
{
uint64_t g_ref = g->vr4_ref();
bool horizontal_flip = g->horizontal_flip();
std::vector<tileset_vr4_t::pixel_type_t *> *pixel_ref = mTilesetHub.vr4->elements();
tileset_vr4_t::pixel_type_t *color_ref = pixel_ref->at(g_ref);
const string &color = color_ref->minitile();
PaletteImage palImage(Size(8, 8));
unsigned int i = 0;
for (auto c : color)
{
Pos pos = palImage.indexToPosition(i);
palImage.at(pos) = c;
i++;
}
mPaletteImage->copyTile(palImage, n, horizontal_flip);
n++;
}
}
std::shared_ptr<PaletteImage> MegaTile::getImage()
{
return mPaletteImage;
}
} /* namespace tileset */
| 1,501
|
C++
|
.cpp
| 56
| 23.785714
| 94
| 0.691011
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,160
|
Flingy.cpp
|
Wargus_stargus/src/dat/Flingy.cpp
|
/*
* Flingy.cpp
*
* Author: Andreas
*/
#include "Flingy.h"
#include "Logger.h"
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.Flingy");
Flingy::Flingy(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Flingy::~Flingy()
{
}
uint16_t Flingy::sprite()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->sprite()->at(mId);
}
Sprite Flingy::sprite_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Sprite(mDatahub, sprite());
}
uint32_t Flingy::speed()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->speed()->at(mId);
}
uint16_t Flingy::acceleration()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->acceleration()->at(mId);
}
uint32_t Flingy::halt_distance()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->halt_distance()->at(mId);
}
uint8_t Flingy::turn_radius()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->turn_radius()->at(mId);
}
uint8_t Flingy::unused()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->unused()->at(mId);
}
uint8_t Flingy::movement_control()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.flingy->movement_control()->at(mId);
}
} /* namespace dat */
| 1,538
|
C++
|
.cpp
| 59
| 24.118644
| 70
| 0.655715
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,161
|
Techdata.cpp
|
Wargus_stargus/src/dat/Techdata.cpp
|
/*
* Techdata.cpp
*
* Author: Andreas Volz
*/
#include "Techdata.h"
#include "Logger.h"
#include "PropertyNotAvailableException.h"
static Logger logger = Logger("startool.dat.Techdata");
using namespace std;
namespace dat
{
Techdata::Techdata(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Techdata::~Techdata()
{
}
uint16_t Techdata::mineral_cost()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->mineral_cost()->at(mId);
}
uint16_t Techdata::vespene_cost()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->vespene_cost()->at(mId);
}
uint16_t Techdata::research_time()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->research_time()->at(mId);
}
uint16_t Techdata::energy_required()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->energy_required()->at(mId);
}
uint32_t Techdata::unknown4()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->unknown4()->at(mId);
}
uint16_t Techdata::icon()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->icon()->at(mId);
}
uint16_t Techdata::label()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->label()->at(mId);
}
TblEntry Techdata::label_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
if(label() == Techdata::label_none)
{
throw PropertyNotAvailableException(mId, "label_tbl");
}
return mDatahub.stat_txt_tbl_vec.at(label()-1);
}
uint8_t Techdata::race()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->race()->at(mId);
}
uint8_t Techdata::unused()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->unused()->at(mId);
}
bool Techdata::broodwar_flag()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.techdata->broodwar_flag()->at(mId);
}
bool Techdata::has_broodwar_flag()
{
return mDatahub.techdata->has_broodwar_flag();
}
} /* namespace dat */
| 2,288
|
C++
|
.cpp
| 83
| 25.542169
| 69
| 0.673236
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,162
|
Weapon.cpp
|
Wargus_stargus/src/dat/Weapon.cpp
|
/*
* Weapon.cpp
*
* Author: Andreas Volz
*/
#include "Weapon.h"
#include "Logger.h"
using namespace std;
static Logger logger = Logger("startool.dat.Weapon");
namespace dat
{
Weapon::Weapon(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Weapon::~Weapon()
{
}
uint16_t Weapon::label()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->label()->at(mId);
}
TblEntry Weapon::label_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
if(label() == Weapon::label_none)
{
throw PropertyNotAvailableException(mId, "label_tbl");
}
return mDatahub.stat_txt_tbl_vec.at(label()-1);
}
uint32_t Weapon::graphics()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->graphics()->at(mId);
}
Flingy Weapon::graphics_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t graphics_id = graphics();
if(graphics_id == Weapon::graphics_none)
{
throw PropertyNotAvailableException(mId, "graphics_obj");
}
return Flingy(mDatahub, graphics());
}
uint8_t Weapon::explosion()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->explosion()->at(mId);
}
uint16_t Weapon::target_flags()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->target_flags()->at(mId);
}
uint32_t Weapon::minimum_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->minimum_range()->at(mId);
}
uint32_t Weapon::maximum_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->maximum_range()->at(mId);
}
uint8_t Weapon::damage_upgrade()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->damage_upgrade()->at(mId);
}
Upgrade Weapon::damage_upgrade_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Upgrade(mDatahub, damage_upgrade());
}
uint8_t Weapon::weapon_type()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->weapon_type()->at(mId);
}
uint8_t Weapon::weapon_behaviour()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->weapon_behaviour()->at(mId);
}
uint8_t Weapon::remove_after()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->remove_after()->at(mId);
}
uint8_t Weapon::explosive_type()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->explosive_type()->at(mId);
}
uint16_t Weapon::inner_splash_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->inner_splash_range()->at(mId);
}
uint16_t Weapon::medium_splash_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->medium_splash_range()->at(mId);
}
uint16_t Weapon::outer_splash_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->outer_splash_range()->at(mId);
}
uint16_t Weapon::damage_amount()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->damage_amount()->at(mId);
}
uint16_t Weapon::damage_bonus()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->damage_amount()->at(mId);
}
uint8_t Weapon::weapon_cooldown()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->weapon_cooldown()->at(mId);
}
uint8_t Weapon::damage_factor()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->damage_factor()->at(mId);
}
uint8_t Weapon::attack_angle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->attack_angle()->at(mId);
}
uint8_t Weapon::launch_spin()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->launch_spin()->at(mId);
}
uint8_t Weapon::x_offset()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->x_offset()->at(mId);
}
uint8_t Weapon::y_offset()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->y_offset()->at(mId);
}
uint16_t Weapon::error_message()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->error_message()->at(mId);
}
TblEntry Weapon::error_message_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.stat_txt_tbl_vec.at(error_message());
}
uint16_t Weapon::icon()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.weapons->icon()->at(mId);
}
} /* namespace dat */
| 5,044
|
C++
|
.cpp
| 168
| 27.922619
| 70
| 0.656593
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,163
|
Sfx.cpp
|
Wargus_stargus/src/dat/Sfx.cpp
|
/*
* Sound.cpp
*
* Author: Andreas Volz
*/
// project
#include "Sfx.h"
#include "Logger.h"
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.Sound");
Sfx::Sfx(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Sfx::~Sfx()
{
}
uint32_t Sfx::sound_file()
{
return mDatahub.sfxdata->sound_file()->at(mId);
}
TblEntry Sfx::sound_file_tbl()
{
return mDatahub.sfxdata_tbl_vec.at(sound_file()-1);
}
uint8_t Sfx::unknown1()
{
return mDatahub.sfxdata->unknown1()->at(mId);
}
uint8_t Sfx::unknown2()
{
return mDatahub.sfxdata->unknown2()->at(mId);
}
uint8_t Sfx::unknown3()
{
return mDatahub.sfxdata->unknown3()->at(mId);
}
uint8_t Sfx::unknown4()
{
return mDatahub.sfxdata->unknown4()->at(mId);
}
} /* namespace dat */
| 795
|
C++
|
.cpp
| 44
| 16.318182
| 53
| 0.703804
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,164
|
DataHub.cpp
|
Wargus_stargus/src/dat/DataHub.cpp
|
/*
* DataHub.cpp
*
* Author: Andreas Volz
*/
// Local
#include "Logger.h"
#include "luagen.h"
#include "DataHub.h"
#include "StringUtil.h"
#include "Grp.h"
#include "Unit.h"
#include "Preferences.h"
#include "FileUtil.h"
#include "Hurricane.h"
// System
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.DataHub");
DataHub::DataHub(std::shared_ptr<Hurricane> hurricane) :
KaitaiConverter(hurricane)
{
init_units_dat();
init_orders_dat();
init_weapons_dat();
init_flingy_dat();
init_sprites_dat();
init_images_dat();
init_sfxdata_dat();
init_portdata_dat();
init_upgrades_dat();
init_techdata_dat();
init_mapdata_dat();
init_stat_txt_tbl();
init_images_tbl();
init_sfxdata_tbl();
init_portdata_tbl();
init_mapdata_tbl();
init_iscript_bin();
}
DataHub::~DataHub()
{
}
void DataHub::init_units_dat()
{
string sc_arr_units_dat = "arr\\units.dat";
m_units_stream = mHurricane->extractStream(sc_arr_units_dat);
m_units_ks = make_shared<kaitai::kstream>(&*m_units_stream);
units = make_shared<units_dat_t>(m_units_ks.get());
}
void DataHub::init_orders_dat()
{
string sc_arr_orders_dat = "arr\\orders.dat";
m_orders_stream = mHurricane->extractStream(sc_arr_orders_dat);
m_orders_ks = make_shared<kaitai::kstream>(&*m_orders_stream);
orders = make_shared<orders_dat_t>(m_orders_ks.get());
}
void DataHub::init_weapons_dat()
{
string sc_arr_weapons_dat = "arr\\weapons.dat";
m_weapons_stream = mHurricane->extractStream(sc_arr_weapons_dat);
m_weapons_ks = make_shared<kaitai::kstream>(&*m_weapons_stream);
weapons = make_shared<weapons_dat_t>(m_weapons_ks.get());
}
void DataHub::init_flingy_dat()
{
string sc_arr_flingy_dat = "arr\\flingy.dat";
m_flingy_stream = mHurricane->extractStream(sc_arr_flingy_dat);
m_flingy_ks = make_shared<kaitai::kstream>(&*m_flingy_stream);
flingy = make_shared<flingy_dat_t>(m_flingy_ks.get());
}
void DataHub::init_sprites_dat()
{
string sc_arr_sprites_dat = "arr\\sprites.dat";
m_sprites_stream = mHurricane->extractStream(sc_arr_sprites_dat);
m_sprites_ks = make_shared<kaitai::kstream>(&*m_sprites_stream);
sprites = make_shared<sprites_dat_t>(m_sprites_ks.get());
}
void DataHub::init_images_dat()
{
string sc_arr_images_dat = "arr\\images.dat";
m_images_stream = mHurricane->extractStream(sc_arr_images_dat);
m_images_ks = make_shared<kaitai::kstream>(&*m_images_stream);
images = make_shared<images_dat_t>(m_images_ks.get());
}
void DataHub::init_sfxdata_dat()
{
string sc_arr_sfxdata_dat = "arr\\sfxdata.dat";
m_sfxdata_stream = mHurricane->extractStream(sc_arr_sfxdata_dat);
m_sfxdata_ks = make_shared<kaitai::kstream>(&*m_sfxdata_stream);
sfxdata = make_shared<sfxdata_dat_t>(m_sfxdata_ks.get());
}
void DataHub::init_portdata_dat()
{
string sc_arr_portdata_dat = "arr\\portdata.dat";
m_portdata_stream = mHurricane->extractStream(sc_arr_portdata_dat);
m_portdata_ks = make_shared<kaitai::kstream>(&*m_portdata_stream);
portdata = make_shared<portdata_dat_t>(m_portdata_ks.get());
}
void DataHub::init_upgrades_dat()
{
string sc_arr_upgrades_dat = "arr\\upgrades.dat";
m_upgrades_stream = mHurricane->extractStream(sc_arr_upgrades_dat);
m_upgrades_ks = make_shared<kaitai::kstream>(&*m_upgrades_stream);
upgrades = make_shared<upgrades_dat_t>(m_upgrades_ks.get());
}
void DataHub::init_techdata_dat()
{
string sc_arr_techdata_dat = "arr\\techdata.dat";
m_techdata_stream = mHurricane->extractStream(sc_arr_techdata_dat);
m_techdata_ks = make_shared<kaitai::kstream>(&*m_techdata_stream);
techdata = make_shared<techdata_dat_t>(m_techdata_ks.get());
}
void DataHub::init_mapdata_dat()
{
string sc_arr_mapdata_dat = "arr\\mapdata.dat";
m_mapdata_stream = mHurricane->extractStream(sc_arr_mapdata_dat);
m_mapdata_ks = make_shared<kaitai::kstream>(&*m_mapdata_stream);
mapdata = make_shared<mapdata_dat_t>(m_mapdata_ks.get());
}
void DataHub::init_stat_txt_tbl()
{
string sc_rez_stat_txt_tbl = "rez\\stat_txt.tbl";
std::shared_ptr<std::istream> tbl_stream = mHurricane->extractStream(sc_rez_stat_txt_tbl);
std::shared_ptr<kaitai::kstream> stat_txt_ks = make_shared<kaitai::kstream>(&*tbl_stream);
Tbl stat_txt;
/*std::vector<TblEntry>*/
stat_txt_tbl_vec = stat_txt.convertFromStream(stat_txt_ks);
/*int vec_pos = 0;
// This below splits the big string vector to smaller ones per type. I found later that regarding the data index one
// big file is easier to handle. But maybe I change my mind later to enable this again...
stat_txt_units_tbl_vec.resize(units->flingy()->size());
std::copy(stat_txt_tbl_vec.begin() + vec_pos, stat_txt_tbl_vec.begin() + units->flingy()->size(), stat_txt_units_tbl_vec.begin());
vec_pos += units->flingy()->size();
stat_txt_weapons_tbl_vec.resize(weapons->label()->size());
std::copy(stat_txt_tbl_vec.begin() + vec_pos, stat_txt_tbl_vec.begin() + vec_pos + weapons->label()->size(), stat_txt_weapons_tbl_vec.begin());
vec_pos += weapons->label()->size();
stat_txt_error_messages_tbl_vec.resize(weapons->error_message()->size());
std::copy(stat_txt_tbl_vec.begin() + vec_pos, stat_txt_tbl_vec.begin() + vec_pos + weapons->error_message()->size(), stat_txt_error_messages_tbl_vec.begin());
vec_pos += weapons->error_message()->size();
stat_txt_upgrades_tbl_vec.resize(upgrades->label()->size());
std::copy(stat_txt_tbl_vec.begin() + vec_pos, stat_txt_tbl_vec.begin() + vec_pos + upgrades->label()->size(), stat_txt_upgrades_tbl_vec.begin());
vec_pos += upgrades->label()->size();
stat_txt_orders_tbl_vec.resize(orders->label()->size());
std::copy(stat_txt_tbl_vec.begin() + vec_pos, stat_txt_tbl_vec.begin() + vec_pos + orders->label()->size(), stat_txt_orders_tbl_vec.begin());
vec_pos += orders->label()->size();
stat_txt_techdata_tbl_vec.resize(techdata->label()->size());
std::copy(stat_txt_tbl_vec.begin() + vec_pos, stat_txt_tbl_vec.begin() + vec_pos + techdata->label()->size(), stat_txt_techdata_tbl_vec.begin());
vec_pos += techdata->label()->size();*/
}
void DataHub::init_images_tbl()
{
string sc_arr_images_tbl = "arr\\images.tbl";
std::shared_ptr<std::istream> tbl_stream = mHurricane->extractStream(sc_arr_images_tbl);
std::shared_ptr<kaitai::kstream> images_tbl_ks = make_shared<kaitai::kstream>(&*tbl_stream);
Tbl images_tbl;
images_tbl_vec = images_tbl.convertFromStream(images_tbl_ks);
}
void DataHub::init_sfxdata_tbl()
{
string sc_arr_sfxdata_tbl = "arr\\sfxdata.tbl";
std::shared_ptr<std::istream> tbl_stream = mHurricane->extractStream(sc_arr_sfxdata_tbl);
std::shared_ptr<kaitai::kstream> sfxdata_tbl_ks = make_shared<kaitai::kstream>(&*tbl_stream);
Tbl sfxdata_tbl;
sfxdata_tbl_vec = sfxdata_tbl.convertFromStream(sfxdata_tbl_ks);
}
void DataHub::init_portdata_tbl()
{
string sc_arr_portdata_tbl = "arr\\portdata.tbl";
std::shared_ptr<std::istream> tbl_stream = mHurricane->extractStream(sc_arr_portdata_tbl);
std::shared_ptr<kaitai::kstream> portdata_tbl_ks = make_shared<kaitai::kstream>(&*tbl_stream);
Tbl portdata_tbl;
portdata_tbl_vec = portdata_tbl.convertFromStream(portdata_tbl_ks);
}
void DataHub::init_mapdata_tbl()
{
string sc_arr_mapdata_tbl = "arr\\mapdata.tbl";
std::shared_ptr<std::istream> tbl_stream = mHurricane->extractStream(sc_arr_mapdata_tbl);
std::shared_ptr<kaitai::kstream> mapdata_tbl_ks = make_shared<kaitai::kstream>(&*tbl_stream);
Tbl mapdata_tbl;
mapdata_tbl_vec = mapdata_tbl.convertFromStream(mapdata_tbl_ks);
}
void DataHub::init_iscript_bin()
{
string sc_iscript_bin = "scripts\\iscript.bin";
m_iscript_stream = mHurricane->extractStream(sc_iscript_bin);
m_iscript_ks = make_shared<kaitai::kstream>(&*m_iscript_stream);
iscript = make_shared<iscript_bin_t>(m_iscript_ks.get());
/* This code creates a map to access the iscripts by image ID */
for(unsigned int i = 0; i < iscript->entree_offsets()->size(); i++)
{
auto entree_offset = iscript->entree_offsets()->at(i);
uint16_t iscript_id = entree_offset->iscript_id();
m_iscriptImageEntreeMap[iscript_id] = i;
}
}
uint16_t DataHub::getIScriptImage(uint16_t index)
{
return m_iscriptImageEntreeMap.at(index);
}
} /* namespace dat */
| 8,354
|
C++
|
.cpp
| 206
| 37.902913
| 160
| 0.712159
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,165
|
TblEntry.cpp
|
Wargus_stargus/src/dat/TblEntry.cpp
|
/*
* TblEntry.cpp
*
* Author: Andreas Volz
*/
// project
#include "TblEntry.h"
#include "Logger.h"
// system
#include <string>
using namespace std;
static Logger logger = Logger("startool.dat.TblEntry");
namespace dat
{
TblEntry::TblEntry()
{
m_shortcut_pos = -1;
m_shortcut = ' ';
}
TblEntry::~TblEntry()
{
}
std::string TblEntry::name1()
{
LOG4CXX_TRACE(logger, LOG_CUR_FUNC + "()=" + m_name1);
return m_name1;
}
std::string TblEntry::name2()
{
LOG4CXX_TRACE(logger, LOG_CUR_FUNC + "()=" + m_name2);
return m_name2;
}
std::string TblEntry::name3()
{
LOG4CXX_TRACE(logger, LOG_CUR_FUNC + "()=" + m_name3);
return m_name3;
}
int TblEntry::shortcut_pos()
{
LOG4CXX_TRACE(logger, LOG_CUR_FUNC + "()=" + to_string(m_shortcut_pos));
return m_shortcut_pos;
}
std::string TblEntry::shortcut()
{
LOG4CXX_TRACE(logger, LOG_CUR_FUNC + "()=" + m_shortcut);
return m_shortcut;
}
} /* namespace dat */
| 937
|
C++
|
.cpp
| 48
| 17.645833
| 74
| 0.675429
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,166
|
Unit.cpp
|
Wargus_stargus/src/dat/Unit.cpp
|
/*
* Unit.cpp
*
* Author: Andreas Volz
*/
// project
#include "Unit.h"
#include "Logger.h"
// system
#include <iostream>
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.Unit");
Unit::Unit(DataHub &datahub, unsigned int id, const std::string &identString) :
ObjectAccess(datahub, id),
mIdentString(identString)
{
}
Unit::~Unit()
{
}
std::string Unit::getIDString()
{
// trace at least the id string that we know where we are
LOG4CXX_TRACE(logger, mIdentString + "=>" + LOG_CUR_FUNC + "()");
return mIdentString;
}
TblEntry Unit::name_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.stat_txt_tbl_vec.at(mId);
}
uint8_t Unit::flingy()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->flingy()->at(mId);
}
Flingy Unit::flingy_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Flingy(mDatahub, flingy());
}
uint16_t Unit::subunit1()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->subunit1()->at(mId);
}
Unit Unit::subunit1_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t subunit_id = subunit1();
if(subunit_id == Unit::subunit_none)
{
throw PropertyNotAvailableException(mId, "subunit1_obj");
}
return Unit(mDatahub, subunit_id, "<subunit2>");
}
uint16_t Unit::subunit2()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->subunit2()->at(mId);
}
Unit Unit::subunit2_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t subunit_id = subunit2();
if(subunit_id == Unit::subunit_none)
{
throw PropertyNotAvailableException(mId, "subunit2_obj");
}
return Unit(mDatahub, subunit_id, "<subunit2>");
}
uint16_t Unit::infestation()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t infestation = 0;
try
{
// only for units of ID 106-201 (buildings)
infestation = mDatahub.units->infestation()->at(mId-106);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_DEBUG(logger, string("Exception: infestation(") + to_string(infestation) + ")");
throw PropertyNotAvailableException(mId, "infestation");
}
return infestation;
}
Unit Unit::infestation_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t infestation_id = infestation();
if(infestation_id == Unit::infestation_none)
{
throw PropertyNotAvailableException(mId, "infestation_obj");
}
return Unit(mDatahub, infestation_id, "<infestation>");
}
uint32_t Unit::construction_animation()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->construction_animation()->at(mId);
}
Image Unit::construction_animation_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t construction_animation_id = construction_animation();
if(construction_animation_id == Unit::construction_none)
{
throw PropertyNotAvailableException(mId, "construction_animation_obj");
}
return Image(mDatahub, construction_animation_id);
}
uint8_t Unit::unit_direction()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->unit_direction()->at(mId);
}
uint8_t Unit::shield_enable()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->shield_enable()->at(mId);
}
uint16_t Unit::shield_amount()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->shield_amount()->at(mId);
}
uint32_t Unit::hitpoints()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->hit_points()->at(mId)->hitpoints();
}
uint8_t Unit::elevation_level()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->elevation_level()->at(mId);
}
uint8_t Unit::unknown()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->unknown()->at(mId);
}
uint8_t Unit::rank()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->rank()->at(mId);
}
uint8_t Unit::ai_computer_idle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ai_computer_idle()->at(mId);
}
Order Unit::ai_computer_idle_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Order(mDatahub, ai_computer_idle());
}
uint8_t Unit::ai_human_idle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ai_human_idle()->at(mId);
}
Order Unit::ai_human_idle_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Order(mDatahub, ai_human_idle());
}
uint8_t Unit::ai_return_to_idle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ai_return_to_idle()->at(mId);
}
Order Unit::ai_return_to_idle_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Order(mDatahub, ai_return_to_idle());
}
uint8_t Unit::ai_attack_unit()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ai_attack_unit()->at(mId);
}
Order Unit::ai_attack_unit_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Order(mDatahub, ai_attack_unit());
}
uint8_t Unit::ai_attack_move()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ai_attack_move()->at(mId);
}
Order Unit::ai_attack_move_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Order(mDatahub, ai_attack_move());
}
uint8_t Unit::ground_weapon()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ground_weapon()->at(mId);
}
Weapon Unit::ground_weapon_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint8_t ground_weapon_id = mDatahub.units->ground_weapon()->at(mId);
// strange logic in the data. If the weapon links to a index bigger than weapon then it's 'none'
if(ground_weapon_id >= mDatahub.weapons->label()->size())
{
LOG4CXX_TRACE(logger, string("Exception: ground_weapon_obj > size"));
throw PropertyNotAvailableException(mId, "ground_weapon_obj");
}
return Weapon(mDatahub, ground_weapon_id);
}
uint8_t Unit::max_ground_hits()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->max_ground_hits()->at(mId);
}
uint8_t Unit::air_weapon()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->air_weapon()->at(mId);
}
Weapon Unit::air_weapon_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint8_t air_weapon_id = mDatahub.units->air_weapon()->at(mId);
// strange logic in the data. If the weapon links to a index bigger than weapon then it's 'none'
if(air_weapon_id >= mDatahub.weapons->label()->size())
{
LOG4CXX_TRACE(logger, string("Exception: air_weapon_obj > size"));
throw PropertyNotAvailableException(mId, "air_weapon_obj");
}
return Weapon(mDatahub, air_weapon_id);
}
uint8_t Unit::max_air_hits()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->max_air_hits()->at(mId);
}
uint8_t Unit::ai_internal()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->ai_internal()->at(mId);
}
units_dat_t::special_ability_flags_type_t* Unit::special_ability_flags()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->special_ability_flags()->at(mId);
}
uint8_t Unit::target_acquisition_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->target_acquisition_range()->at(mId);
}
uint8_t Unit::sight_range()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->sight_range()->at(mId);
}
uint8_t Unit::armor_upgrade()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->armor_upgrade()->at(mId);
}
units_dat_t::unit_size_enum_t Unit::unit_size()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->unit_size()->at(mId);
}
uint8_t Unit::armor()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->armor()->at(mId);
}
units_dat_t::right_click_action_enum_t Unit::right_click_action()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->right_click_action()->at(mId);
}
uint16_t Unit::ready_sound()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t ready_sound = 0;
try
{
// only unit IDs < 106 have ready_sound
ready_sound = mDatahub.units->ready_sound()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: ready_sound(") + to_string(ready_sound) + ")");
throw PropertyNotAvailableException(mId, "ready_sound");
}
return ready_sound;
}
Sfx Unit::ready_sound_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t ready_sound_id = ready_sound();
if(ready_sound_id == Unit::sound_none)
{
LOG4CXX_TRACE(logger, string("Exception: ready_sound_obj(") + to_string(ready_sound_id) + ")");
throw PropertyNotAvailableException(mId, "ready_sound_obj");
}
Sfx sfx(mDatahub, ready_sound_id);
return sfx;
}
uint16_t Unit::what_sound_start()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->what_sound_start()->at(mId);
}
uint16_t Unit::what_sound_end()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->what_sound_end()->at(mId);
}
std::vector<Sfx> Unit::what_sound_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
std::vector<Sfx> sfx_vector;
uint16_t what_sound_start_id = what_sound_start();
uint16_t what_sound_end_id = what_sound_end();
if((what_sound_start_id || what_sound_end_id) == Unit::sound_none)
{
LOG4CXX_TRACE(logger, string("Exception: what_sound_obj(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "what_sound_obj");
}
for(unsigned int i = what_sound_start_id; i <= what_sound_end_id; i++)
{
Sfx sfx(mDatahub, i);
sfx_vector.push_back(sfx);
}
return sfx_vector;
}
uint16_t Unit::piss_sound_start()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t piss_sound_start = 0;
try
{
// only unit IDs < 106 have piss_sound_start
piss_sound_start = mDatahub.units->piss_sound_start()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: piss_sound_start(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "piss_sound_start");
}
return piss_sound_start;
}
uint16_t Unit::piss_sound_end()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t piss_sound_end = 0;
try
{
// only unit IDs < 106 have piss_sound_end
piss_sound_end = mDatahub.units->piss_sound_end()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: piss_sound_end(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "piss_sound_end");
}
return piss_sound_end;
}
std::vector<Sfx> Unit::piss_sound_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
std::vector<Sfx> sfx_vector;
uint16_t piss_sound_start_id = piss_sound_start();
uint16_t piss_sound_end_id = piss_sound_end();
if((piss_sound_start_id || piss_sound_end_id) == Unit::sound_none)
{
LOG4CXX_TRACE(logger, string("Exception: piss_sound_obj(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "piss_sound_obj");
}
for(unsigned int i = piss_sound_start_id; i <= piss_sound_end_id; i++)
{
Sfx sfx(mDatahub, i);
sfx_vector.push_back(sfx);
}
return sfx_vector;
}
uint16_t Unit::yes_sound_start()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t yes_sound_start = 0;
try
{
// only unit IDs < 106 have yes_sound_start
yes_sound_start = mDatahub.units->yes_sound_start()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: piss_sound_start(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "yes_sound_start");
}
return yes_sound_start;
}
uint16_t Unit::yes_sound_end()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t yes_sound_end = 0;
try
{
// only unit IDs < 106 have yes_sound_end
yes_sound_end = mDatahub.units->yes_sound_end()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: yes_sound_end(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "yes_sound_end");
}
return yes_sound_end;
}
std::vector<Sfx> Unit::yes_sound_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
std::vector<Sfx> sfx_vector;
uint16_t yes_sound_start_id = yes_sound_start();
uint16_t yes_sound_end_id = yes_sound_end();
if((yes_sound_start_id || yes_sound_end_id) == Unit::sound_none)
{
LOG4CXX_TRACE(logger, string("Exception: yes_sound_obj(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "yes_sound_obj");
}
for(unsigned int i = yes_sound_start_id; i <= yes_sound_end_id; i++)
{
Sfx sfx(mDatahub, i);
sfx_vector.push_back(sfx);
}
return sfx_vector;
}
units_dat_t::staredit_placement_box_type_t* Unit::staredit_placement_box()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->staredit_placement_box()->at(mId);
}
units_dat_t::addon_position_type_t* Unit::addon_position()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
units_dat_t::addon_position_type_t* addon = nullptr;
try
{
// Exists only for units of ID 106-201 (buildings)
addon = mDatahub.units->addon_position()->at(mId-106);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: addon_position(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "addon_position");
}
return addon;
}
units_dat_t::unit_dimension_type_t *Unit::unit_dimension()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->unit_dimension()->at(mId);
}
uint16_t Unit::portrait()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->portrait()->at(mId);
}
Portrait Unit::portrait_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t portrait_id = portrait();
if (portrait_id == Unit::portrait_none)
{
LOG4CXX_TRACE(logger, string("Exception: portrait_obj(") + to_string(mId) + ")");
throw PropertyNotAvailableException(mId, "portrait_obj");
}
Portrait portrait(mDatahub, portrait_id);
return portrait;
}
uint16_t Unit::mineral_cost()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->mineral_cost()->at(mId);
}
uint16_t Unit::vespene_cost()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->vespene_cost()->at(mId);
}
uint16_t Unit::build_time()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->build_time()->at(mId);
}
uint16_t Unit::requirements()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->requirements()->at(mId);
}
units_dat_t::staredit_group_flags_type_t* Unit::staredit_group_flags()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->staredit_group_flags()->at(mId);
}
uint8_t Unit::supply_required()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->supply_required()->at(mId);
}
uint8_t Unit::space_provided()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->space_provided()->at(mId);
}
uint16_t Unit::build_score()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->build_score()->at(mId);
}
uint16_t Unit::destroy_score()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->destroy_score()->at(mId);
}
// TODO: a unit_map_string_string_tbl() might be helpful...
uint16_t Unit::unit_map_string()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->unit_map_string()->at(mId);
}
uint8_t Unit::broodwar_flag()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->broodwar_flag()->at(mId);
}
units_dat_t::staredit_availability_flags_type_t* Unit::staredit_availability_flags()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.units->staredit_availability_flags()->at(mId);
}
bool Unit::is_format_bw()
{
return mDatahub.units->is_format_bw();
}
} /* namespace dat */
| 17,710
|
C++
|
.cpp
| 548
| 29.75
| 99
| 0.659151
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,167
|
Sprite.cpp
|
Wargus_stargus/src/dat/Sprite.cpp
|
/*
* Sprite.cpp
*
* Author: Andreas Volz
*/
#include "Sprite.h"
#include "Logger.h"
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.Sprite");
Sprite::Sprite(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Sprite::~Sprite()
{
}
uint16_t Sprite::image()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t image_id = 0;
/*
* The data deep dive shows that there're some unused units which request a sprite/image
* which is available first in Broodwar for this Sprite. I could only assume that this is an error.
* Therefore this is just mapped to 0. No problem as such units are never used in the normal game.
* This is just to draw the unit in test code.
*/
if (mId < mDatahub.sprites->image()->size())
{
image_id = mDatahub.sprites->image()->at(mId);
LOG4CXX_TRACE(logger, string("image(") + to_string(image_id) + ")");
}
else
{
LOG4CXX_TRACE(logger, string("not found image->at(") + to_string(mId) + ") mapped to 0");
}
return image_id;
}
Image Sprite::image_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return Image(mDatahub, image());
}
uint8_t Sprite::health_bar()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t health_bar = 0;
try
{
// This property is only available from unit index 130 to num_lines
health_bar = mDatahub.sprites->health_bar()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: health_bar(") + to_string(health_bar) + ")");
throw PropertyNotAvailableException(mId, "health_bar");
}
return health_bar;
}
uint8_t Sprite::unknown2()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint8_t unknown2 = 0;
/*
* The data deep dive shows that there're some unused units which request a unknown property
* which is available first in Broodwar for this Sprite. I could only assume that this is an error.
* Therefore this is just mapped to 0. No problem as such units are never used in the normal game.
*/
if (mId < mDatahub.sprites->unknown2()->size())
{
unknown2 = mDatahub.sprites->unknown2()->at(mId);
LOG4CXX_TRACE(logger, string("unknown2(") + to_string(unknown2) + ")");
}
else
{
LOG4CXX_TRACE(logger, string("not found unknown2->at(") + to_string(mId) + ") mapped to 0");
}
return unknown2;
}
bool Sprite::is_visible()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint8_t is_visible = 1;
/*
* The data deep dive shows that there're some unused units which request a unknown property
* which is available first in Broodwar for this Sprite. I could only assume that this is an error.
* Therefore this is just mapped to 0. No problem as such units are never used in the normal game.
* We map it to 1 to let this units draw for test cases.
*/
if (mId < mDatahub.sprites->is_visible()->size())
{
is_visible = mDatahub.sprites->is_visible()->at(mId);
LOG4CXX_TRACE(logger, string("is_visible(") + to_string(is_visible) + ")");
}
else
{
LOG4CXX_TRACE(logger, string("not found is_visible->at(") + to_string(mId) + ") mapped to 1");
}
return is_visible;
}
uint8_t Sprite::select_circle_image_size()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t select_circle_image_size = 0;
try
{
// This property is only available from unit index 130 to num_lines
select_circle_image_size = mDatahub.sprites->select_circle_image_size()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: select_circle_image_size(") + to_string(select_circle_image_size) + ")");
throw PropertyNotAvailableException(mId, "select_circle_image_size");
}
return select_circle_image_size;
}
uint8_t Sprite::select_circle_vertical_pos()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint16_t select_circle_vertical_pos = 0;
try
{
// This property is only available from unit index 130 to num_lines
select_circle_vertical_pos = mDatahub.sprites->select_circle_vertical_pos()->at(mId);
}
catch (const std::out_of_range& oor)
{
LOG4CXX_TRACE(logger, string("Exception: select_circle_vertical_pos(") + to_string(select_circle_vertical_pos) + ")");
throw PropertyNotAvailableException(mId, "select_circle_vertical_pos");
}
return select_circle_vertical_pos;
}
} /* namespace dat */
| 4,566
|
C++
|
.cpp
| 134
| 31
| 122
| 0.680291
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,168
|
PropertyNotAvailableException.cpp
|
Wargus_stargus/src/dat/PropertyNotAvailableException.cpp
|
/*
* PropertyNotAvailableException.cpp
*
* Author: Andreas Volz
*/
#include "PropertyNotAvailableException.h"
using namespace std;
namespace dat {
const char *PropertyNotAvailableException::what() const throw()
{
static string s;
s = "Property '";
s += m_property;
s += "' not existing for parent: ";
s += to_string(m_parent_id);
return static_cast <const char *>(s.c_str());
}
} /* namespace dat */
| 427
|
C++
|
.cpp
| 18
| 21.5
| 63
| 0.694789
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,169
|
Image.cpp
|
Wargus_stargus/src/dat/Image.cpp
|
/*
* Image.cpp
*
* Author: Andreas Volz
*/
#include "Image.h"
#include "Logger.h"
#include "platform.h"
#include "StringUtil.h"
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.Image");
Image::Image(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Image::~Image()
{
}
uint32_t Image::grp()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->grp()->at(mId);
}
TblEntry Image::grp_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images_tbl_vec.at(grp()-1);
}
bool Image::gfx_turns()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->gfx_turns()->at(mId);
}
bool Image::clickable()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->clickable()->at(mId);
}
bool Image::use_full_iscript()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->use_full_iscript()->at(mId);
}
bool Image::draw_if_cloaked()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->draw_if_cloaked()->at(mId);
}
images_dat_t::draw_function_enum_t Image::draw_function()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->draw_function()->at(mId);
}
images_dat_t::remapping_enum_t Image::remapping()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->remapping()->at(mId);
}
uint32_t Image::iscript()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->iscript()->at(mId);
}
IScript Image::iscript_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return IScript(mDatahub, iscript());
}
uint32_t Image::shield_overlay()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->shield_overlay()->at(mId);
}
TblEntry Image::shield_overlay_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t overlay = shield_overlay();
if(overlay == Image::overlay_none)
{
throw PropertyNotAvailableException(mId, "shield_overlay_tbl");
}
return mDatahub.images_tbl_vec.at(overlay);
}
uint32_t Image::attack_overlay()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->attack_overlay()->at(mId);
}
TblEntry Image::attack_overlay_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t overlay = attack_overlay();
if(overlay == Image::overlay_none)
{
throw PropertyNotAvailableException(mId, "attack_overlay_tbl");
}
return mDatahub.images_tbl_vec.at(overlay);
}
uint32_t Image::damage_overlay()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->damage_overlay()->at(mId);
}
TblEntry Image::damage_overlay_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t overlay = damage_overlay();
if(overlay == Image::overlay_none)
{
throw PropertyNotAvailableException(mId, "damage_overlay_tbl");
}
return mDatahub.images_tbl_vec.at(overlay);
}
uint32_t Image::special_overlay()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->special_overlay()->at(mId);
}
TblEntry Image::special_overlay_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t overlay = special_overlay();
if(overlay == Image::overlay_none)
{
throw PropertyNotAvailableException(mId, "special_overlay_tbl");
}
return mDatahub.images_tbl_vec.at(overlay);
}
uint32_t Image::landing_dust_overlay()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->landing_dust_overlay()->at(mId);
}
TblEntry Image::landing_dust_overlay_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t overlay = landing_dust_overlay();
if(overlay == Image::overlay_none)
{
throw PropertyNotAvailableException(mId, "landing_dust_overlay_tbl");
}
return mDatahub.images_tbl_vec.at(overlay);
}
uint32_t Image::lift_off_dust_overlay()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.images->lift_off_dust_overlay()->at(mId);
}
TblEntry Image::lift_off_dust_overlay_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint32_t overlay = lift_off_dust_overlay();
if(overlay == Image::overlay_none)
{
throw PropertyNotAvailableException(mId, "lift_off_dust_overlay_tbl");
}
return mDatahub.images_tbl_vec.at(overlay);
}
std::string Image::getIDString()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
string image_name("image_" + to_string(mId) + "_" + grp_tbl().name1());
replaceString("\\", "_", image_name);
//fs::path p(image_name);
image_name = to_lower(cutFileEnding(image_name));
//cout << "image_name: " << image_name << endl;
return image_name;
}
} /* namespace dat */
| 5,257
|
C++
|
.cpp
| 171
| 28.210526
| 76
| 0.661706
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,170
|
IScript.cpp
|
Wargus_stargus/src/dat/IScript.cpp
|
/*
* IScript.cpp
*
* Author: Andreas Volz
*/
// Local
#include "IScript.h"
#include "Logger.h"
// system
#include <iostream>
#include <iterator>
using namespace std;
static Logger logger = Logger("startool.dat.IScript");
namespace dat
{
IScript::IScript(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, datahub.getIScriptImage(id))
{
}
IScript::~IScript()
{
}
std::vector<iscript_bin_t::opcode_type_t*> IScript::getAnimationScript(IScript::AnimationType animationType)
{
return getAnimationScript(static_cast<unsigned int>(animationType));
}
std::vector<iscript_bin_t::opcode_type_t*> IScript::getAnimationScript(unsigned int animationType)
{
LOG4CXX_TRACE(logger, to_string(mId) + ":" + to_string(animationType) + "=>" + LOG_CUR_FUNC + "()");
iscript_bin_t::scpe_type_t* scpe = mDatahub.iscript->scpe()->at(mId);
std::vector<iscript_bin_t::scpe_content_type_t*>* scpe_content_vec = scpe->scpe_content();
// calculate the offset hash list per iscript (TODO: maybe cache this?)
unordered_set<uint16_t> scpe_offset_table;
for(auto scpe_content : *scpe_content_vec)
{
scpe_offset_table.insert(scpe_content->scpe_opcode_offset());
}
iscript_bin_t::scpe_content_type_t* scpe_content = scpe_content_vec->at(animationType);
opcode_list_type_t* opcode_list_type = scpe_content->scpe_opcode_list();
// if kaitai animation script object is null give a empty vector back (TODO: maybe change design)
if(!opcode_list_type)
{
return std::vector<iscript_bin_t::opcode_type_t*>();
}
// else... parse the object....
std::vector<kaitai::kstruct*>* opcode_vec_ks = opcode_list_type->read_list(scpe_offset_table);
std::vector<iscript_bin_t::opcode_type_t*> opcode_vec(opcode_vec_ks->size());
std::transform(opcode_vec_ks->begin(), opcode_vec_ks->end(), opcode_vec.begin(),
[](auto ptr) {return static_cast<iscript_bin_t::opcode_type_t*>(ptr); });
return opcode_vec;
}
int8_t IScript::getAnimationCount()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.iscript->scpe()->at(mId)->num_scpe_content();
}
bool IScript::is_format_bw()
{
return !mDatahub.iscript->version_tag();
}
} /* namespace dat */
| 2,232
|
C++
|
.cpp
| 61
| 33.934426
| 108
| 0.708896
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,171
|
Order.cpp
|
Wargus_stargus/src/dat/Order.cpp
|
/*
* Order.cpp
*
* Author: Andreas Volz
*/
// project
#include "Order.h"
#include "Logger.h"
static Logger logger = Logger("startool.dat.Order");
using namespace std;
namespace dat
{
Order::Order(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Order::~Order()
{
}
uint16_t Order::label()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->label()->at(mId);
}
TblEntry Order::label_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.stat_txt_tbl_vec.at(label());
}
bool Order::use_weapon_targeting()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->use_weapon_targeting()->at(mId);
}
uint8_t Order::unknown2()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown2()->at(mId);
}
uint8_t Order::unknown3()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown3()->at(mId);
}
uint8_t Order::unknown4()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown4()->at(mId);
}
uint8_t Order::unknown5()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown5()->at(mId);
}
uint8_t Order::interruptible()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->interruptible()->at(mId);
}
uint8_t Order::unknown7()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown7()->at(mId);
}
uint8_t Order::queueable()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->queueable()->at(mId);
}
uint8_t Order::unknown9()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown9()->at(mId);
}
uint8_t Order::unknown10()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown10()->at(mId);
}
uint8_t Order::unknown11()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown11()->at(mId);
}
uint8_t Order::unknown12()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown12()->at(mId);
}
uint8_t Order::targeting()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->targeting()->at(mId);
}
Weapon Order::targeting_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint8_t targeting_id = targeting();
// strange logic in the data. If the weapon links to a index bigger than weapon then it's 'none'
if(targeting_id >= mDatahub.weapons->label()->size())
{
LOG4CXX_TRACE(logger, string("Exception: targeting_obj > size"));
throw PropertyNotAvailableException(mId, "targeting_obj");
}
return Weapon(mDatahub, targeting_id);
}
uint8_t Order::energy()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->energy()->at(mId);
}
Techdata Order::energy_obj()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
uint8_t energy_id = energy();
// strange logic in the data. If the weapon links to a index bigger than weapon then it's 'none'
if(energy_id >= mDatahub.techdata->label()->size())
{
LOG4CXX_TRACE(logger, string("Exception: energy_obj > size"));
throw PropertyNotAvailableException(mId, "energy_obj");
}
return Techdata(mDatahub, energy_id);
}
uint8_t Order::animation()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->animation()->at(mId);
}
uint8_t Order::highlight()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->highlight()->at(mId);
}
uint8_t Order::unknown17()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->unknown17()->at(mId);
}
uint8_t Order::obscured_order()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.orders->obscured_order()->at(mId);
}
} /* namespace dat */
| 4,310
|
C++
|
.cpp
| 144
| 27.770833
| 98
| 0.656818
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
752,172
|
Portrait.cpp
|
Wargus_stargus/src/dat/Portrait.cpp
|
/*
* Portrait.cpp
*
* Author: Andreas Volz
*/
#include "Portrait.h"
#include "Logger.h"
#include "StringUtil.h"
#include "platform.h"
using namespace std;
namespace dat
{
static Logger logger = Logger("startool.dat.Portrait");
Portrait::Portrait(DataHub &datahub, unsigned int id) :
ObjectAccess(datahub, id)
{
}
Portrait::~Portrait()
{
}
uint32_t Portrait::video_idle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata->video_idle()->at(mId);
}
TblEntry Portrait::video_idle_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata_tbl_vec.at(video_idle() - 1);
}
uint32_t Portrait::video_talking()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata->video_talking()->at(mId);
}
TblEntry Portrait::video_talking_tbl()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata_tbl_vec.at(video_talking() - 1);
}
uint8_t Portrait::change_idle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata->change_idle()->at(mId);
}
uint8_t Portrait::change_talking()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata->change_talking()->at(mId);
}
uint8_t Portrait::unknown1_idle()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata->unknown1_idle()->at(mId);
}
uint8_t Portrait::unknown1_talking()
{
LOG4CXX_TRACE(logger, to_string(mId) + "=>" + LOG_CUR_FUNC + "()");
return mDatahub.portdata->unknown1_talking()->at(mId);
}
std::string Portrait::getIDString(const std::string &portrait)
{
string portrait_name(portrait);
replaceString("\\", "/", portrait_name);
fs::path p(portrait_name);
portrait_name = to_lower(p.parent_path().string());
//cout << "portrait_name: " << portrait_name << endl;
return portrait_name;
}
} /* namespace dat */
| 2,019
|
C++
|
.cpp
| 70
| 26.842857
| 70
| 0.677035
|
Wargus/stargus
| 127
| 24
| 9
|
GPL-2.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.